#include<iostream>
#include<cmath>
using namespace std;
int main()
{int n;
cin>>n;
if(n==0)
cout<<"1";
else
if(n==1||n%4==1)
cout<<"8";
else
if(n==2||n%4==2)
cout<<"4";
else
if(n==3||n%4==3)
cout<<"2";
else
if(n==4||n%4==0)
cout<<"6";
}

#include<bits/stdc++.h>
using namespace std;
inline char gt(){
    static char buf[100000],*p1=buf,*p2=buf;
    return
        p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
    char ch=gt();
    int sm=0;
    while(!(ch>='0'&&ch<='9'))
        ch=gt();
    while(ch>='0'&&ch<='9')
        sm=sm*10+ch-48,ch=gt();
    return sm;
}
char a[]={"8426"};
int n;
int main(){
    n=read();
    if(!n)putchar('1');
    else putchar(a[(n-1)%4]);
    return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int A []={8,4,2,6};
    int n;
        cin>>n;
        if (n==0)cout<<"1";
        else cout<<A[(n-1)%4];

}

#include <iostream>
using namespace std;

int main() {
	int n,m;
	cin>>n;
	if(n==0){
		m=1;
	}
	else if(n%4==0){
		m=6;
	}
	else if(n%4==1){
		m=8;
	}
	else if(n%4==2){
		m=4;
	}
	else{
		m=2;
	}
	cout<<m<<endl;
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <numeric>
#include <functional>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <fstream>

using namespace std;

long long gcd(long long a, long long b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

long long lcm(long long  a, long long  b) {
	return a * b / gcd(a, b);
}

int mod = 1000000007;

inline int add(int a, int b) {
	int ret = a + b;
	if (ret >= mod)
		ret -= mod;
	return ret;
}

int main() {
	int n, e = 1;
	scanf("%d", &n);
	if (!n) e = 1;
	else {
		int t = n % 4;
		if (!t) e = 6;
		while (t--)e *= 8;
	}
	cout << e % 10;
	/*system("pause");*/
	return 0;
}

#include <stdio.h>
int main(int argc, char *argv[])
{
	int a[5]={6,8,4,2,6};
    int n,i;
    while(~scanf("%d", &n))
    {
		if (n==0)
    	{
        	printf("1\n");
    	}
    	else
    	{
        	printf("%d\n",a[n%4]);
    	}
	}
    return 0;
}

#include <iostream>
using namespace std;
long long pow(int a, int b, int MOD)
{
    long long x=1,y=a;
    while(b > 0)
    {
        if(b%2 == 1)
        {
            x=(x*y);
            if(x>MOD) x%=MOD;
        }
        y = (y*y);
        if(y>MOD) y%=MOD;
        b /= 2;
    }
    return x;
}
int main()
{
   int n;
  cin>> n;
  cout << pow(1738,n,10);
  return 0;
}

#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cstdlib>
const double pi = acos(-1);
using namespace std;

int main()
{
	int x[4]={6,8,4,2},y;
	cin>>y;
	if (y==0)
        cout<<1;
    else
        cout<<x[y%4];

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[]={6,8,4,2};
    if(n==0) cout<<1<<endl;
    else cout<<arr[n%4]<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n==0) cout<<"1";
    else{
        int p=n%4;
        if(p==0) cout<<"6";
        else{
        int g=pow(8,p);
        cout<<(g%10);}
    }
    return 0;
}

// fuck ratings, i am in love with learning process

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
ll expo(ll a,ll b)
{
	ll res=1;
	if(b==0)return 1;
	if(b==1)return a;
	while(b>0)
	{
		if(b&1)res=(res*a)%10;
		a=(a*a)%10;b=b/2;
	}
	return res;
}
void solve()
{
	ll n;
	cin>>n;
/*	if(n==0)cout<<"1\n";

	else if(n%4==1)cout<<"8\n";
	else if(n%4==2)cout<<"4\n";
	else if(n%4==3)cout<<"2\n";
	else if(n%4==0)cout<<"6\n";*/
	cout<<expo(8, n)<<"\n";
}

int main()
{

	fastio;

	solve();
}

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    long long int ans;
    scanf("%d",&n);
    if(n==0) {
        printf("1");
        return 0;
    }if(n%4==0) ans=6;
    else if(n%4==1) ans = 8;
    else if(n%4==2) ans = 4;
    else if(n%4==3) ans = 2;
    cout<<ans;
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
    long int n;
    cin>>n;
    if(n==0)
    	cout<<"1";
    else{
   	 int a[4]={8,4,2,6};
   	 int k=n%4;
  	  if(k==0)
    		k=4;
   	 cout<<a[k-1];
   }
    return 0;
}

#include<iostream>
using namespace std;
main()
{
	int n,i,num=8,sum;
	cin>>n;
	num=n%4;
	if(n==0)
	{
	cout<<"1";
	return 0;}
	switch(num)
	{
		case 1:cout<<"8";break;
		case 2:cout<<"4";break;
		case 3:cout<<"2";break;
		case 0:cout<<"6";break;
	}
}

#include<iostream>
using namespace std;
int n,k=1,a,b;
main() {

cin>>n;
if(n>=4){n=n%4;
    switch(n){

    case 1: cout<<8; return 0;
case 2: cout<<4; return 0;
    case 3: cout<<2; return 0;
case 0: cout<<6; return 0;}

}
    switch(n){

    case 1: cout<<8; return 0;
case 2: cout<<4; return 0;
    case 3: cout<<2; return 0;
case 0: cout<<1; return 0;
    }}

//be name khoda
#include <iostream>
using namespace std;
int main ()
{
	long long int a , b;
	cin>>a;
	b=a%4;
	if(a==0)
		cout<<"1";

	else if ( b==0)
		cout<<"6";
	else if (b==1)
		cout<<"8";
	else if (b==2)
		cout<<"4";
	else if (b==3)
		cout<<"2";
	return 0;

}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n; cin >> n;
    int arr[4] = {8,4,2,6};
    if (n==0) { cout << 1; return 0;}
    n = (n-1)%4;
    cout << arr[n];
}

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
int main()
{
	int n;
	cin >> n;
	if (n == 0){
		cout << "1" << endl;
	}
	else{
		if (n % 4 == 1)
			cout << "8" << endl;
		if (n % 4 == 2)
			cout << "4" << endl;
		if (n % 4 == 3)
			cout << "2" << endl;
		if (n % 4 == 0)
			cout << "6" << endl;
	}

	return 0;
}

#include <iostream>

using namespace std;

int main()
{
    long long int n ;
    cin>>n;
    if (n == 0)
    {
        cout<<n+1;
        return 0;
    }
    long long int cnt =8;
    long long int cons = 8;
    n = n % 8;
    if (n == 0)
        n=8;
    //cout<<n<<endl;
    for (long long int i =1 ;i < n ;i++)
    {
        cnt = cnt*cons ;
        cnt = cnt%10;
    }
    cout<<cnt;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(){

    long long int n,x,d = 1;

    cin >> n;

    if(!(n%10) && n >= 10){
        if(n%4 == 1)
            cout << 8;
        else if (n%4 == 0)
            cout << 6;
        else if (n%4 == 2)
            cout << 4;
        else if (n%4 == 3)
            cout << 2;
    }
    else{
        for(int i = 0;i < n%100;i++)
            d = (d%10)*8;
        cout << d%10;
    }
    return 0;
}

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int n;
    cin>>n;
    if(n==0)cout<<1;
    else{
    if(n%2==0)
    {   if(n%4==0)
            cout<<6;
        else
            cout<<4;
    }
    else
    {
        if(n%4==3)
            cout<<2;
        else
            cout<<8;
    }}
    return 0;
}

#include<iostream>
using namespace std;
#define CI cin >>
#define CO cout <<
#define GE getchar()
#define AND &&
#define OR ||
#define NOT(x) !##x
int main()
{
	long long a;
	CI a;
	if (a == 0)
		CO 1;
	else if (a % 4 == 1)
		CO 8;
	else if(a%4==2)
	{
		CO 4;
	}
	else if (a % 4 == 3)
	{
		CO 2;
	}
	else
	{
		CO 6;
	}
	GE;
	GE;
	GE;
	return 0;
}

#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main()
{
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    long long x;cin>>x;
    //long long ans=pow(8,x);
    //cout<<ans<<endl;
    //string str=(string)ans;
   /* vector<long long>v;
    while(ans>0)
    {
        v.push_back(ans%10);
        ans/=10;
    }
    cout<<v[0]<<endl; */
   // cout<<4096%10<<endl;
    if(x%4==0 && x>0)
    {
         //long long ans=pow(8,4);
         cout<<6<<endl;

    }
    else
    {
        long long ans=pow(8,x%4);
        cout<<ans%10<<endl;
    }

   return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
        long long int n;
        cin>>n;

        if(n==0)
        {
            cout<<"1";
            return 0;
        }

        if(n%4==0)
            cout<<"6"<<endl;
        else if(n%4==1)
            cout<<"8"<<endl;
        else if(n%4==2)
            cout<<"4"<<endl;
        else if(n%4==3)
            cout<<"2"<<endl;

        return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{

long long number , sum=1378;
cin >> number;
long long arr[11];

if (number == 0)
{
    cout << 1;
    return 0;
}
int i;
arr[1] = 1378%10;
for(i = 2 ; i < 11 ; i++)
{
        sum*=1378;
        if(sum%10 == arr[1])
            break;
        arr[i] = sum%10;
}
arr[0] = arr[i-1];
cout<<arr[number%(i-1)] << endl;

 return 0;
}

#include<bits/stdc++.h>

using namespace std;
int main()
{
        int  i,j,k;
     int  n,x=8,y=8;
        cin>>n;

        if(n==0)
        {
            cout<<"1";
            return 0;
        }

        if(n%4==0)
            cout<<"6"<<endl;
        else if(n%4==1)
            cout<<"8"<<endl;
        else if(n%4==2)
            cout<<"4"<<endl;
        else if(n%4==3)
            cout<<"2"<<endl;

        return 0;
}

#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <math.h>
#include <ctype.h>

#define REP(i, n) for (int i = 1; i <= n; i++)
#define REP0(i, n) for (int i = 0; i < n; i++)
#define pi 2 * acos(0.0)
#define M 100001
#define N 101
#define INF 0x7fffffff

typedef long long int lli;

using namespace std;
/*

*/

lli power(lli a,lli n, lli p){
    lli res=1;
    while(n){
        if(n&1){
            res=(res*a)%p;
            n--;
        }
        else{
            a=(a*a)%p;
            n/=2;
        }
    }
    return res;
}

int main()
{
#ifdef sxk
    freopen("in.txt", "r", stdin);
#endif
    int n;cin>>n;
    cout<<power(8,n,10)<<endl;
    return 0;
}

# include <iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    long long n;
    map<int ,int>mp;
    mp[0]=8;
    mp[1]=4;
    mp[2]=2;
    mp[3]=6;
    cin>>n;
    n=n-1;
    if(n==-1)
        cout<<1;
    else
    cout<<mp[n%4];
   return 0;
}

#include <iostream>

using namespace std;

int main()
{
   long long x ;
   cin >> x ;
   int m = 8 ;
   int n = 4 ;
   int l ;
    if (x>1000)
    {
        x = x%1000 ;
        if (x==1)
        {
            cout << 8 ;
        }
        else if ( x==2)
        {
            cout << 4 ;
        }
        else if ( x == 0)
        {
            cout << 6 ;
        }
        else if ( x>2 )
        {
            for (int i =2 ; i<x ; i++)
                {
                    l = (m+n) % 10 ;
                    m= n ;
                    n=l ;
        }
            cout << l ;
        }
    }

   else
   {
         if (x==1)
        {
            cout << 8 ;
        }
        else if ( x==2)
        {
            cout << 4 ;
        }
        else if ( x == 0)
        {
            cout << 1 ;
        }
        else if ( x>2 )
        {
            for (int i =2 ; i<x ; i++)
                {
                    l = (m+n) % 10 ;
                    m= n ;
                    n=l ;
                }
            cout << l ;
        }
   }
    return 0;
}

#include<iostream>
#include<map>
#include<string>
#include<stdio.h>
#include<memory.h>
#include <queue>
#include <deque>
#include<algorithm>
#pragma warning (disable : 4996)
#include<set>
#include <cmath>
#include<utility>
#include<iomanip>
#include<sstream>
using namespace std;

int main()
{
	//freopen("in.txt", "r", stdin);

	long long int key;
	int n[] = { 6 , 8 , 4 , 2 };
     cin >> key;
	if (key==0) cout << 1 << endl;
	else cout << n[key%4] << endl;

	return 0;
}

#include <iostream>
using namespace std;
#define ulli unsigned long long int
 void ans(ulli power, ulli base){
 ulli res=1;
   while(power){

     if(power%2==0){
       base=(base*base)%10;
       power=power/2;}
       else{
         power--;
         res=(res*base)%10;
     }
   }
   cout<<res<<endl;
 }
int main() {
  ulli n; //power
  cin>>n;
  //as 8 os congruent to 1378
  ans(n, 8);
}

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<sstream>
#include<map>
#include<set>
#include<utility>
#include<queue>
#include<stack>

using namespace std;

int main(){
    //freopen("a.in", "r", stdin);
    long long int n, j=1;
    cin >> n;
    if(n==0) cout << 1 << endl;
    else{
        if((n-1) % 4 == 0) cout << 8 << endl;
        else if((n-2) % 4 == 0) cout << 4 << endl;
        else if((n-3) % 4 == 0) cout << 2 << endl;
        else if((n-4) % 4 == 0) cout << 6 << endl;
    }
    return 0;
}

#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int res[] = {8, 4, 2, 6};
    cout << (n ? res[(n - 1)%4] : 1) << endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int N;
cin>>N;
if(N==0)
    cout<<1;
   else  if(N%4==0)
        cout<<6;
    else if(N%4==1)
        cout<<8;
    else if(N%4==2)
        cout<<4;
    else if(N%4==3)
        cout<<2;

    return 0;
}

#include  <iostream>
using namespace std;

int main(){
	int n;
	int arr[4]={6,8,4,2};
	cin>>n;
	if(n==0) cout<<"1"<<endl;
	else cout<<arr[n%4]<<endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	cin>>n;
		if(n==0)
	{
		cout<<"1";
		return 0;
	}
	n%=4;

	switch(n)
	{
		case 0:
		cout<<"6";
		break;
		case 1:
		cout<<"8";
		break;
		case 2:
		cout<<"4";
		break;
		case 3:
		cout<<"2";
		break;
	}

	return 0;
}

#include <iostream>
#include <string.h>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <sstream>
#define fast ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);
#define ll long long
#define fri(x,n)	for(int i = x ; i < n ; i++)
#define frj(x,n)	for(int j = x ; j < n ; j++)
#define inf 1e9
#define MAX 200000+9
int dx[2] = { 0,1 };
int dy[2] = { 1,0 };
using namespace std;
#define PB push_back

int main()
{

	ll n;
	cin >> n;
	if (n == 0)
	{
		cout << 1;
		return 0;
	}

	if (n % 4 == 1)
		cout << 8;
	else if (n % 4 == 2)
		cout << 4;
	else if (n % 4 == 3)
		cout << 2;
	else
		cout << 6;

	return 0;
}

#include<iostream>
using namespace std;
int main()
{
	int n,x, i;
	cin >> n;
	x = 8;
	if (n == 0)
	{
		cout << 1;
	}
	else
	{
		n = n % 4;
		if (n == 0)
			n = 4;
		for (i = 1; i < n; i++)
		{
			x = x*8;
			x = x % 10;
		}
		cout << x;
	}
	return 0;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,ans=1,k=1378;
    cin>>n;
    while(n>0)
    {
        if(n%2==1){
            ans=(ans*k)%1000000000;
            n--;
        }
        k=(k*k)%1000000000;
        n=n/2;
    }
    cout<<(ans)%10<<endl;
}

#include<iostream>
using namespace std;

#define lli long long int

lli lastDigit(lli a, lli n, lli p)
{
   lli res = 1;

   while(n)
   {
      if(n % 2)
      {
        res = ( res * a ) % p;
        n--;
      }
      else
      {
        a = (a * a) % p;

        n /= 2;
      }

   }

   return res;
}
int main()
{

  int n;
  cin>>n;
  int p = lastDigit(1378,n,10);
  cout<<p<<endl;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int x=n%4;
    if(n==0)
        cout<<1;
    else if(x==0)
        cout<<6;
    else if(x==1)
    cout<<8;
    else if(x==2)
    cout<<4;
    else if(x==3)
    cout<<2;
}

#include <iostream>
using namespace std;
#include<cmath>
#include<math.h>
int main()
{
   long long n;
   cin>>n;
 int s = n % 4;
  if(n==0)
    cout<<1<<endl;
  else if( s == 0)
  {
     int x =  pow(8,4);
     cout<<x%10<<endl;
  }
  else if( s == 1)
  {
      int x =  pow(8,1);
     cout<<x%10<<endl;
  }
  else if( s == 2)
  {
      int x =  pow(8,2);
     cout<<x%10<<endl;
  }
  else
  {
      int x =  pow(8,3);
     cout<<x%10<<endl;
  }
    return 0;
}

#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    long long n; cin >> n;
    int num = n%4;

    if(n==0)
    {
        cout << 1 << endl;
    }
    else if(num==0)
    {
        cout << 6 << endl;
    }
    else if(num==1)
    {
        cout << 8 << endl;
    }
    else if(num==2)
    {
        cout << 4 << endl;
    }
    else if(num==3)
    {
        cout << 2 << endl;
    }

}

#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;

#define MX 262500
#define MOD 1000000007
typedef long long  LL;
const double  PI=acos(-1.0);

template <typename T>
inline T myMax(T x, T y)
{
    return (x > y)? x: y;
}

int main()
{
    //freopen("iin.txt", "r", stdin);
    //  freopen("1.out", "w", stdout);
    // cout << myMax<double>(3.0, 7.0) << endl;
    long long Tk,n ;

    while(scanf("%lld",&n)==1)
    {
        if(n==0)
            printf("1\n");
        else if(n%4==0)
            printf("6\n");
        else if(n%4==3)
            printf("2\n");
        else if(n%4==2)
            printf("4\n");
        else if(n%4==1)
            printf("8\n");

    }

    return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int z;
    cin>>z;
    if(z==0)
    {
        cout<<1;
        return 0;
    }
    if(z%4==1)
    {
        cout<<8<<endl;
    }
    else if(z%4==2)
    {
        cout<<4;
    }
    else if(z%4==3)
    {
        cout<<2;
    }
    else
    {
        cout<<6;
    }
    return 0;
}

#include <iostream>
using namespace std;

int n;
int a[] = {8,4,2,6};

int main(){
	cin >> n;
	n--;
	if (n == -1){
		a[0] = 1 ;
		n = 0;
	}
	else n %= 4;

	cout << a[n];

	return 0;
}

#include <iostream>
using namespace std;

int main() {
	long long int a;
	cin>>a;
	if(a!=0){
		if(a%4==0){
			cout<<6;
		}
		else if(a%4==3){
			cout<<2;
		}
		else if(a%4==2){
			cout<<4;
		}
		else{
			cout<<8;
		}
	}
	else{
		cout<<1;
	}
}

#include<bits/stdc++.h>
using namespace std;
int main(){
long long int a,b=8,c=0,d,e,f=0,sum=0,mx=-99999;
cin>>a;
if(a==0){
	cout<<1;
}
else if(a%4==2){
	cout<<4;
}
else if(a%4==3){
	cout<<2;
}
else if(a%4==0){
	cout<<6;
}
else if(a%4==1){
	cout<<8;
}
}

#include <iostream>

using namespace std;
int main(){
	unsigned long int x;
	cin >> x;
	if (x == 0){
		cout << 1;
	return 0;
	}
	x = 3 * x % 4;
	if (x == 0)x = 4;
	cout << (1 << x) % 10;
	}

#include<iostream>
using namespace std;
int main(){
    long n;
    cin>>n;
    if(n==0)
    cout<<1;
    else if(n==1)
    cout<<8;
    else if(n%4==2)
    cout<<4;
    else if(n%4==3)
    cout<<2;
    else if(n%4==0)
    cout<<6;
    else if(n%4==1)
    cout<<8;
    return 0;
}

    #include<bits/stdc++.h>

    using namespace std;

    typedef  unsigned long long ll;

   int main(){
ll n;
cin >> n;
ll ans = 1, a = 8;
while(n){
    if(n&1) ans = (ans*a)%10;
    a = (a*a)%10;
    n = n >> 1;
}
cout << ans%10;
   }

#include<sstream>
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
	int x;
	cin >> x;
	if (x == 0)
	{
		cout << 1;
		return 0;
	}

	int arr[4] = { 8,4,2,6 };
	x = (x - 1) % 4;

	cout << arr[x] << endl;

	return 0;
}

#include <stdio.h>
#include <stdlib.h>
int vi(int n)
{
    int i;
    int a=8;
    int ans=1;
    while(n!=0)
    {

        if(n&1==1)
            ans=(ans%10)*(a%10);
        n=(n>>1);
        a=(a%10)*(a%10);
    }
    return ans%10;
}
int main()
{
    int n;
    scanf("%d",&n);
    printf("%d",vi(n));
    return 0;
}

#include<iostream>
using namespace std;
int main(){
	int n, x = 8;
	cin >> n;
	if (!n) { cout << 1; return 0; }
	for (int i = 0; i < (n - 1)%4; ++i) x *= 8, x %= 10;
	cout << x;
	return 0;
}

#include <iostream>
using namespace std;

int main()
{
	int n;
	while( cin >> n ){
		int ans[] = { 6, 8, 4, 2 };
		cout << ( n == 0 ? 1 : ans[ n % 4 ] ) << endl;
	}
	return 0;
}

 #include <bits/stdc++.h>

 using namespace std;
int n,t[100000],s,x,m;
string c;

 int main(){
    cin >> n;
    if(n==0)cout<< 1;
    else{
    if(n%4==0)cout << 6;
    else if(n%4==1)cout << 8;
    else if(n%4==2)cout << 4;
    else if(n%4==3)cout << 2;}
 }

#include <bits/stdc++.h>

using namespace std;

#define M 10

typedef long long ll;

ll mod(ll b, ll e, ll m) {
    if(e == 0) return 1;
    ll c = 1;
    ll ep = 1;
    for( ; ep <= e ; ep++) {
        c = (b * c) % m;
    }
    return c;
}

ll modB(ll b, ll e, ll m) {
    if(e == 0) return 1;
    ll res = 1;
    b %= m;
    while(e) {
        if(e % 2) {
            res = (res * b) % m;
        }
        e /= 2;
        b = (b * b) % m;
    }
    return res;
}

ll mod_ex(ll b, ll e, ll m) {
    if(m == 0) return 1;
    ll res = 1;
    b = b  % m;
    while(e) {
        if(e % 2) res = (res * b) % m;
        e >>= 1;
        b = (b * b) % m;
    }
    return res;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif // ONLINE_JUDGE

    int n;
    cin >> n;
    cout << mod_ex(1378, n, 10);
    return 0;
}

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    long long int n,ans,h=0;
    cin>>n;
    if(n>99999999)
    {
        long long int h1=n,h2=n,h3;
        h1/=10000;
        h1*=1000;
        h2/=100;
        h2*=100;
        h3=n-h2;
        n=h1+h3;
    }
    for(long long int i=1;i<=n;i++)
    {
        if(h==4)
        {
            h=0;
        }

        h++;
    }
    if(h==0)
        cout<<1;
    else if(h==1)
            cout<<8;
    else if(h==2)
        cout<<4;
    else if(h==3)
        cout<<2;
    else if(h==4)
        cout<<6;
    //cout<<endl<<"n "<<n;
    /*ans=pow(8,n);
    h=ans/10;
    h*=10;
    cout<<ans-h;
    cout<<h;*/

    return 0;
}

#include <iostream>

using namespace std;

int main()
{
    long long num=1;
    long long n;
    cin>>n;
    if (n%4==1)
    {
        num=8;
    }
    else  if (n%4==2)
    {
        num=4;
    }
    else  if (n%4==3)
    {
        num=2;
    }
    else
    {
        num=6;
    }
    if (n==0)
        num=1;

    cout<<num;
    return 0;
}

#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <bitset>
using namespace std;

typedef long long ll;
int main() {
    ll n;
    cin>>n;
    if (n==0) {
        cout<<1<<endl;
        return 0;
    }
    int n2=n%4;
    if (n2==1) cout<<8<<endl;
    else if (n2==2) cout<<4<<endl;
    else if (n2==3) cout<<2<<endl;
    else if (n2==0) cout<<6<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
 int power(int base, int exp,int mod)
{
    if(exp == 0)
     return 1;

    int p=power(base, exp/2,mod);
    p=(p*p)% mod;
    return (exp%2 == 0)?p:(base * p)%mod;
}

int main(void){

    long long int x,y,arr[]={1,1,4,4,2,1,1,4,4,2};
 cin>>y;

cout<<power(8,y,10)<<endl;

}

#include<iostream>

using namespace std;

int main ()
{  int n;
    cin>>n;
    if(n==0)
    cout<<1;
    else if(n%4==0)
    cout<<6;
    else if(n%4==1)
    cout<<8;
    else if(n%4==2)
    cout<<4;
    else if(n%4==3)
    cout<<2;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){//8 4 2 6
	int possible_values[4]={6,8,4,2};
	int n;
	cin>>n;
	if(n==0)cout<<1;
	else{
	cout<<possible_values[n%4];
	}
}

#include<bits/stdc++.h>
using namespace std;
long long  n,i;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;

     if( n==0 ){
        cout<<1<<endl;
     }else if( (n%4)==1 ) {
        cout<<8<<endl;
    } else if( (n%4)==2 ) {
        cout<<4<<endl;
    } else if( (n%4)==3 ) {
        cout<<2<<endl;
    } else {
        cout<<6<<endl;
    }
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
   int b,c;
	cin>>b;

	if(b==0)
	cout<<1<<endl;
    c=b%4;
    if(b!=0&&c==0)
    cout<<6<<endl;
    if(c==1)
    cout<<8<<endl;
    if(c==2)
    cout<<4<<endl;
    if(c==3)
    cout<<2<<endl;

	return 0;
}

/*
		Author : Saurav Lal
				{ Love in Experiences :-) }
*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(),a.rend()
#define int long long
#define ll long long
#define vi vector<int>
#define vip vector<pii>
#define mod1 998244353
#define mod 1000000007
#define endl "\n"
#define loop(i,a,b) for(int i=a;i<b;i++)
#define bloop(i,a,b) for(int i=a;i>=b;i--)
#define testcase  int t; cin>>t; while(t--)
#define vii(v,n,m,a) vector<vector<int>>v(n,vi(m,a))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);

using namespace __gnu_pbds;
using namespace std;

int max(int a, int b) { return (a > b)? a : b; }

int min(int a, int b) { return (a < b)? a : b; }

/*************************************************************************/

int32_t main() {

	FIO
	// testcase
	{
		int n;cin>>n;
		if(n==0)
		{
		    cout<<1;
		    return 0;
		}
		if(n%4==0)
    		cout<<6;
    	if(n%4==1)
    	    cout<<8;
    	if(n%4==2)
    	    cout<<4;
    	if(n%4==3)
        	cout<<2;
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n;
    cin >> n;
    if ( n==0 ) cout << 1 << endl;
    else if ( n%4==1 ) cout << 8 << endl;
    else if ( n%4==2 ) cout << 4 << endl;
    else if ( n%4==3 ) cout << 2 << endl;
    else if ( n%4==0 ) cout << 6 << endl;
    return 0;
}

#include <iostream>
using namespace std;
int main()
{
    int n,a[4]={8,4,2,6};
    cin>>n;
    if(n==0)
        cout<<1;
    else
        cout<<a[(n-1)%4];
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define w(e) int e ; cin >> e ; while (e--)
#define ll long long
#define endl "\n"
#define mod  10000000007
#define pi 3.141592653589793
#define setbit(x) __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)

int32_t main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int n ;
        cin>>n;

        if(n==0)
        {
            cout<<"1";
            return 0;
        }

        if(n%4==0)
            cout<<"6"<<endl;
        else if(n%4==1)
            cout<<"8"<<endl;
        else if(n%4==2)
            cout<<"4"<<endl;
        else if(n%4==3)
            cout<<"2"<<endl;

        return 0;
}

#include <iostream>
#include<string>
#include<map>

using namespace std;

typedef long long ll;

int main(){

	int n;cin >> n;

	int a[] = {8 , 4 , 2 , 6};

	if(n == 0)

		cout << 1;
	else if((n - 1) % 4 == 0)
		cout << a[0];

	else if((n - 2) % 4 == 0)
		cout << a[1];

	else if((n - 3) % 4 == 0)
		cout << a[2];

	else
		cout << a[3];

	cout << "\n";
}

#include <iostream>
using namespace std;
main()
{
	int n;
	cin >> n;
	if(n == 0)
	{
		cout << 1;
	}
	else{

	if(n % 4 == 0)
	{
		cout << 6;
	}
	else{
		if(n % 4 == 3)
		{
			cout << 2;
		}
		else{
			if(n % 4 == 2)
			{
				cout << 4;
			}
			else{
				if(n % 4 == 1)
				{
					cout << 8;
				}
			}
		}
	}
	}
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll n;
	scanf("%lld",&n);
	ll a[10]={6,8,4,2};
	if(n!=0) printf("%lld",a[n%4]);
	else printf("1");
	return 0;
}

# include <iostream>

using namespace std;

int main(void)
{
    int n;
    cin >> n;

    if (n == 0)
    {
        cout << '1' << endl;
    }
    else
    {
        if(n%4 == 0)
            cout << '6' << endl;
        else if(n%4 == 1)
            cout << '8' << endl;
        else if(n%4 == 2)
            cout << '4' << endl;
        else
            cout << '2' << endl;
    }
    return 0;
}

#include<bits/stdc++.h>
#define all(v)      ((v).begin()),  ((v).end())
#define sz(v)        ((int)((v).size()))
typedef long long ll;
using namespace std;
int main(void) {
	ios_base::sync_with_stdio(false);
		cin.tie(NULL);

		int n;
		cin>>n;
		if(n==0)
			cout<<"1";
		else if(n%4==1)
			cout<<8;
		else if(n%4==2)
			cout<<4;
		else if(n%4==3)
			cout<<2;
		else if(n%4==0) cout<<6;

		for(int i=0;i<1000000;++i);
		for(int i=0;i<1000000;++i);
		for(int i=0;i<1000000;++i);
		for(int i=0;i<1000000;++i);

	return 0;
}

    #include <iostream>
    #include <bits/stdc++.h>
    #include <string>
    #include <algorithm>
    using namespace std;

    int main()
    {
    	int n;
    	cin>>n;
    	if(n%4==0){
    		if(n==0)
    			cout<<1;
    		else
    		     cout<<6;}
    	if(n%4==1)
    		cout<<8;
    	if(n%4==2)
    		cout<<4;
    	if(n%4==3)
    		cout<<2;

    	return 0;
    }

#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	int a[4]={6,8,4,2};
	long long b,ans=0;
	cin>>b;
	if( b == 0 ){
	cout<<1;
	}
	else {
	b%=4;
	cout<<a[b];
	}

}

#include<bits/stdc++.h>
using namespace std;

#define lli long long int

int power(lli num, lli pow, int mod){
    int res=1;

    while(pow){
        if(pow%2){
            res = (res*num)%mod;
            pow--;
        }
        else{
            num = (num*num)%mod;
            pow/=2;
        }
    }
    return res;
}

int main(){
    int n;
    cin>>n;

    cout<<power(8, n, 10);
    return 0;
}

#include<iostream>
#include <vector>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	if (n == 0) cout << 1;
	else if (n % 4 == 1) cout << 8 << endl;
	else if (n % 4 == 2) cout << 4 << endl;
	else if (n % 4 == 3)cout << 2 << endl;
	else if (n % 4 == 0)cout << 6 << endl;

	return 0;
}

#include <bits/stdc++.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits>
#include <algorithm>
#include <cstdlib>
#include <bitset>
#include <math.h>
#include <numeric>
#include <sstream>
#include <set>
#include <vector>
#define ll long long
#define pf printf;
#define sf scanf;
using namespace std;

int main(){

	int n,i,k=8,c;
	cin>>n;
	if(n==0){cout<<1;return 0;}
	else if(n%4==1)cout<<8;
	else if(n%4==2)cout<<4;
	else if(n%4==3)cout<<2;
	else if(n%4==0)cout<<6;

return 0;
}

#include <iostream>
using namespace std;
#define MOD 10

int __pow(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = (ans * a) % MOD;  //whenever it is odd
        b /= 2;
        a = (a * a) % MOD;  // whenever it is even
    }
    return ans % MOD;
}

int main() {
    int n;
    cin >> n;
    int k = 8;
    cout << __pow(8, n) << endl;
}

//#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#include<string>
#include<algorithm>
#include<iomanip>
void fast()
{
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
int main()
{
		fast();

	//	freopen("circle.in", "r", stdin);
		//freopen("circle.out", "w", stdout);
		//cout<<fixed<<setprecision(6);

		int n;
		cin>>n;
		if(n)

	{	n%=4;

		switch(n)
		{	case 1:cout<<8;break;
			case 2:cout<<4;break;
			case 3:cout<<2;break;
			case 0:cout<<6;break;
		}}else cout<<1;
//	system("pause");
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    long long a[10]={6,8,4,2};
    if(n!=0)cout<<a[n%4]<<endl;
    else cout<<1<<endl;
    return 0;
}

#include <iostream>
using namespace std;
#define MOD 10

int __pow(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = (ans * a) % MOD;
        b /= 2;
        a = (a * a) % MOD;
    }
    return ans % MOD;
}

int main() {
    int n;
    cin >> n;
    int k = 8;
    cout << __pow(8, n) << endl;
}

#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <math.h>

#define fill(v,val) fill((v).begin(), (v).end(), (val))
#define fillt(tab, n, val) fill((t), (t) + (n) ,(val))
#define MAX 10005
#define INF 9999999
#define in(a,b)  ( (b).find(a) != (b).end())
#define clr(a,b) memset((a), (b), sizeof((a)))
#define pb       push_back
#define all(a)   a.begin(), a.end()
#define mp         make_pair
#define ll long long
const long double pi = 3.141592653589793238L;
/**
*
* @Author Lahia omar

*/

using namespace std;
int tab[] = {6,8,4,2};
int main(int argc, char* argv[]) {
	/*freopen("input.txt","r",stdin);
	freopen("output.txt", "w", stdout);*/
	long long n;
	cin >> n;
	if (n == 0) {
		cout << 1 << endl;
		return 0;
	}
	cout << tab[(n % 4)] << endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long int x, l = 0;
    scanf("%lld", &x);
    if(x==0){
        printf("1\n");
        return 0;
    }

    else{
        x = x%4;
        if(x==0) printf("6\n");
        else if(x==1) printf("8\n");
        else if(x==2) printf("4\n");
        else if(x==3) printf("2\n");

    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int a[]={8,4,2,6};
int main()
{
    int n;
    cin>>n;
    if(n!=0) cout<<a[(n-1)%4]<<endl;
    else cout<<1<<endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

long long n;

long long m(int x)
{
    if(x==0)
    {
        return 1;
    }
    if(x==1)
    {
        return 8;
    }

    int p=1;
    if(x&1)
    {
        p=8;
    }
    int y=m(x/2);

    return (y*y*p)%10;
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    cout<<m(n);
    return 0;
}

#include <iostream>
using namespace std;
int main()
{
long long n=0;
int k=0;
cin>>n;
if (n==0) {k=1; cout<<k<<endl;}
if (n%4==1) {k=8; cout<<k<<endl;}
if (n%4==2) {k=4; cout<<k<<endl;}
if (n%4==3) {k=2; cout<<k<<endl;}
if (n%4==0&&n>0) {k=6; cout<<k<<endl;}
}

#include<iostream>
#include<string>
#include<algorithm>
#include<array>
#include<stdlib.h>
using namespace std;
int main()
{

	long long x;
	cin >> x;
	 if (x == 0)
		cout << "1" << endl;
	else if (x % 4 == 1)
		cout << "8" << endl;
	else if (x % 4 == 2)
		cout << "4" << endl;
	else if (x % 4 == 3)
		cout << "2" << endl;
	else if (x % 4 == 0)
		cout << "6" << endl;

}

//gcc 5.4.0

#include <iostream>
#include  <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(void)
{

	int k, pp, n, m;

// 8 -последняя цифра 8*8= 64, 8*8*8 = 512, 8*8*8*8 = 4096, 8*8*8*8*8 = 32768, а потом опять 4..2..6..8

	cin >> n;
	if(n == 0)
	{
		cout << 1;
		return 0;
	}
	switch(n%4)
	{
		case 0: cout << 6;
			break;
		case 1: cout << 8;
			break;
		case 2: cout << 4;
			break;
		case 3: cout << 2;
			break;
	}

	getchar();
	getchar();
}

#include <iostream>
using namespace std;

int main()
{
	long long n;
	cin >> n;
	if (n <= 4)
	{
		int res = 1;
		for (int i = 1; i <= n; i++)
			res = (res * 1378) % 10;
		cout << res % 10;
		return 0;
	}

	n %= 4;
	switch(n)
	{
	case 0:cout << 6 << endl; break;
	case 1: cout << 8 << endl; break;
	case 2:cout << 4 << endl; break;
	case 3:cout << 2 << endl; break;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int a;
	cin>>a;
	if(a==0)
	cout<<"1";
	else
	{
	a=a%4;
	if(a==1)
	cout<<"8";
	else if(a==2)
	cout<<"4";
	if(a==3)
	cout<<"2";
	else if(a==0)
	cout<<"6";
	return 0;
	}

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
	int t;
	scanf("%d",&t);
	if(t==0)
	cout<<1;
    else if(t%4==0)
    cout<<6;
    else if(t%4==3)
    cout<<2;
    else if(t%4==2)
    cout<<4;
    else
    cout<<8;
}

#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	if (n == 0)
		cout << 1 << endl;
	else if (n % 4 == 1)
		cout << 8 << endl;
	else if (n % 4 == 2)
		cout << 4 << endl;
	else if (n % 4 == 3)
		cout << 2 << endl;
	else
		cout << 6 << endl;
    return 0;
}

 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstring>
using namespace std;
typedef long long int ll;
int main()
{
	int n;
	cin>>n;n--;
	n%=4;
	int a=8;
	for(int i=0;i<n;i++)a*=8;
	cout<<a%10<<endl;
	return 0;
}

#include <iostream>
using namespace std;

int main() {

int n ;
cin>>n;

 if(n%4==1){

	cout<<8;

}
else if(n%4==2){

	cout<<4;
}
else if(n%4==3){

	cout<<2;
}
else{

	cout<<6;
}

	return 0;
}

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    long long int n,ans,h=0;
    cin>>n;
    if(n>99999999)
    {
        cout<<6;
    }
    else
    {

    for(long long int i=1;i<=n;i++)
    {
        if(h==4)
        {
            h=0;
        }

        h++;
    }
    if(h==0)
        cout<<1;
    else if(h==1)
            cout<<8;
    else if(h==2)
        cout<<4;
    else if(h==3)
        cout<<2;
    else if(h==4)
        cout<<6;
    /*ans=pow(8,n);
    h=ans/10;
    h*=10;
    cout<<ans-h;
    cout<<h;*/
    }

    return 0;
}

#include<iostream>
using namespace std;
main()
{
	int n,i,num=8,sum;
	cin>>n;
	num=n%4;
	if(n==0)
	{
	cout<<"0";
	return 0;}
	switch(num)
	{
		case 0:cout<<"8";break;
		case 1:cout<<"4";break;
		case 2:cout<<"2";break;
		case 3:cout<<"6";break;
	}
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int ans=pow(8,n);
cout<<ans%10<<endl;
}

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n,sum,a;
	cin>>n;
	a=pow(8,n);
	a=a%10;
	cout<<a;
	return 0;

}

#include <bits/stdc++.h>
using namespace std;
int n,m,a,b=1;
int main () {
	cin>>n;
	if (n<=1) {cout<<8; return 0;}
	for (int i=0; i<n; i++){
		a=1378*1378;
	}
b=a%10;
	cout<<b;
}

#include<bits/stdc++.h>
using namespace std ;
int n ;
int main()
{
  cin >> n ;
  if( n == 0 )
    cout << 1 ;
  else if(n%4 == 1)
    cout << 8 ;
  else if( n%4 == 2 )
    cout << 2 ;
  else if( n%4 == 3 )
    cout << 4 ;
  else if( n%4 == 0 )
    cout << 6 ;
  return 0 ;
}

#include <iostream>
#include <algorithm>
#define endl '\n'
typedef long long ll;
using namespace std;

// YOU_CAN_SOLVE_IT *_*
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("input.txt","r",stdin);
    int n;
    cin>>n;
    (n%2==0)?cout<<4:cout<<8;
    return 0;
}

#include <iostream>
#include <math.h>
using namespace std;
	long long input ;

int main() {
	int out ;
cin >> input ;
if (input == 0 ) cout << "1";
return 0;
input = input % 4 ;
if (input == 3 ) cout << "2" ;
else if (input == 2 ) cout << "4" ;
else if (input ==  1)cout << "8" ;
else cout << "6" ;

}

#include <iostream>
using namespace std;

long long n;

int main(){
	cin>> n;

	if (n==0){
		cout<< "1" <<endl;
	}
	if (n%4==1 ){
		cout<< "8" <<endl;
	}
	if (n%4==2){
		cout << "4" <<endl;
	}
	if (n%4==3){
		cout << "2"<<endl;
	}
	if (n%4==0){
		cout<< "6" <<endl;
	}
	return 0;
}

#include<iostream>
#include<math.h>

using namespace std;

int main()
{
	int num = 1378;
	int n;
	cin >> n;
	num = pow(1378, n);
	cout << num % 10 << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{

    long long a,b,c,d=1378,i,j,k=0,n,x=1;
cin>>n;
    string st="8426";

    if(n%4==0)
        cout<<st[3]<<endl;
    else if(n%3==0)
        cout<<st[2]<<endl;
 else if(n%2==0)
    cout<<st[1]<<endl;
 else
 cout<<st[0]<<endl;

   return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	long long a,b,ans=0;
	cin>>a;
	if( a % 4 == 0 ){
		cout<<6;
	}
	else if(a%4==1){
		cout<<8;
	}
	else if(a%4==2){
		cout<<4;
	}
	else if(a%4==3){
		cout<<2;
	}

}

#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n==0)
       cout<<1;
    else
       {
           long long int ans = pow(8.0, n);
           ans = ans%10;
           cout<<ans;
       }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
 int n;
 cin >> n;
  n = n%4;
 if(n==1)
 {
      cout << 8 ;
      return 0;
 }
 if(n==2)
 {
      cout << 4 ;
      return 0;
 }
  if(n==3)
 {
      cout << 2 ;
      return 0;
 }
  if(n==0)
 {
      cout << 6 ;
      return 0;
 }
 return 1;
}

#include<iostream>
using namespace std;

int main()
{
	long long int n,d;
	cin >>n;
	d=n;
	if(n==0)
	{
		cout<<0<<endl;
		return 0;
	}
	while(n>0)
	{
		n-=4;
	}
	if(n==1||d==1)
	{
		cout<<8<<endl;
	}
	else if(n==2||d==2)
	{
		cout<<4<<endl;
	}
	else if(n==3||d==3)
	{
		cout<<2<<endl;
	}
	else if(n==0)
	{
		cout<<6<<endl;
	}
	return 0;
}

#include <iostream>
#include "math.h"
using namespace std;
int main(int argc, const char * argv[]) {
    int n,q;
    long long a;
    cin>>n;
    a=pow(1378, n);
    q=a%10;
    printf("%d",q);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j;
    int a[4]={8,4,2,6};
    cin >> n;
    j = n%4;
    j = (j+1)%4;
    cout << a[j] << endl;
}

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int x = 8, y;
	cin >> y;
	long long m = pow(x, y);
	cout << m %10<< endl;
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    long long int n;
    cin>>n;
    long long int x;
    if(n==1)
        cout<<"8"<<endl;
    else if(n==2)
        cout<<"4"<<endl;
    else if(n==3)
        cout<<"2";
    else if(n==4)
        cout<<"6";
    else
    {
        if((n-1)%4==0)
            cout<<"8";
        else if((n-2)%4==0)
            cout<<"4";
        else if((n-3)%4==0)
            cout<<"2";
        else
            cout<<"6";
    }
}

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn=1000000;
int a[maxn];
bool vis[maxn];
int main()
{
    memset(vis,false,sizeof(vis));
    a[0]=1;
    int k=0;
  //  cout<<k<<endl;
    for(int i=1;i<=100;i++)
    {
        a[i]=a[i-1]*8%10;
        if(!vis[a[i]])
        {
            vis[a[i]]=true;
        }
        else
        {
            k=i;
            break;
        }
    }
    k--;
    int n;
    while(cin>>n)
    {
        if(n%k==0)
        {
            cout<<a[k-1]<<endl;
        }
        else
        {
            cout<<a[n%k]<<endl;
        }
    }
    return 0;
}

#include <iostream>
#include <string>
#include <cmath>
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin>>n;
long long r=1;
for(long long i=1;i<=n;i++) r*=8;

cout<<r%10;
}

#include <iostream>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;
	if (n % 4 == 0)
		cout << 6 << endl;
	else if (n % 4 == 3)
		cout << 2 << endl;
	else if (n % 4 == 2)
		cout << 4 << endl;
	else
		cout << 8 << endl;
	//system("pause");
	return 0;
}

#include<stdio.h>
int main ()
{
    long long int n;
    scanf("%lld", &n);
    if (n%5==0)
    {
        printf("0\n");
    }
    else if (n%5==1)
    {
        printf("8\n");
    }
    else if (n%5==2)
    {
        printf("6\n");
    }
    else if (n%5==3)
        printf("4\n");
    else if (n%5==4)
        printf("2\n");
    return 0;
}

#include<cstdlib>
#include <cmath>
#include<iostream>
int main(){

int number;
std::cin >> number;

number = pow(8,number);

std::cout << number % 10;

}

#include <iostream>
using namespace std;

int main (void)
{

	int a [4] = {8, 4, 2, 6};
	long long k = 1, res = 1, n;
	cin >> n;
	if (n < 4){
		cout << a [n];
		return 0;
	}
	for (int i = 0;; i ++) {
		 k = 4 * i;
		 //cout << k << endl;
		 if (k > n) {
			res = i - 1;
			break;
		 } else if (k == n) {
				res = i;
				break;
		 }

		 k = 1;
	}
	//cout << res << endl;
	res = (res == 0) ? 1 : res;
	if (n % (res * 4) == 0) {
		cout << 6;
		return 0;
	}
	cout << a [n % (res * 4) - 1];
	return 0;

	}

#include <bits/stdc++.h>
using namespace std;

int modulo(string n, int a) {
    int num = 0;
    for (int i = 0; i < n.size(); ++i) {
        num = num*10+(n[i]-'0');
        num %= a;
    }
    return num;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    string n; cin >> n;
    int r = modulo(n,4);
    int d = 6;
    if (r) {int p = (int)(pow(8,r)); d = p%10;}
    cout << d << '\n';
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(){

    int n,c;

    cin >> n;

    if(!(n%10) && n >= 10){
        if((n/2)%2){
            cout << 4;
            return 0;
        }
        else if(!((n/2)%2)){
            cout << 6;
            return 0;
        }
    }
    else{
        c = pow(8,n%10);
        cout << c%10;
    }

    return 0;
}

#include <iostream>

using namespace std;

int n, x;

int main(){
    cin >> n;
    n %= 4;
    x = 8;
    if(n == 1){
        cout << 8;
    }
    if(n == 0){
        cout << 6;
    }
    if(n == 3){
        cout << 2;
    }
    if(n == 2){
        cout << 4;
    }
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;

    if(n%4==1){
        cout<<8;
    }
    else if(n%4==2){
        cout<<4;
    }
    else if(n%4==3){
        cout<<2;

    }
    else{
        cout<<8;
    }

}

#include <iostream>
#include<cmath>
using namespace std;
int main ()
{

int n ;
long long  x ;
cin >> n ;
x = pow(8,n);
x=x%10;
cout << x <<endl;
}

#include<bits/stdc++.h>
using namespace std;
int n,a[4]={8,4,6,2};
int main(){
	cin>>n;
	if(n!=0) cout<<a[(n-1)%4]<<endl;
	else cout<<"1"<<endl;
	return 0;
}

//
//  main.cpp
//  CDF
//
//  Created by Ayush Mhaske on 04/11/20.
//

#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int k= n%4;
    if(k==1){cout<<8;}
    if(k==2){cout<<4;}
    if(k==3){cout<<2;}
    if(k==4){cout<<6;}
}

#include <bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
#endif
	int n; cin>>n;
	if(!n) {cout<<1<<endl; return 0;}
	n--;
	int arr[] = {8,4,2,6,8};
	cout<<arr[n%5]<<endl;
}

#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cstdlib>
const double pi = acos(-1);
using namespace std;

int main()
{
	long long x,y;
	cin>>y;
	x=pow(1378.0,y)+0.5;
    cout<<x%10;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(){

    long long int n,x,d = 1;

    cin >> n;

    if(!(n%10)){
        if(n%4 == 1)
            cout << 8;
        else if (n%4 == 0)
            cout << 6;
        else if (n%4 == 2)
            cout << 4;
        else if (n%4 == 3)
            cout << 2;
    }
    else{
        for(int i = 0;i < n%100;i++)
            d = (d%10)*8;
        cout << d%10;
    }
    return 0;
}

#include <iostream>
using namespace std;

int main(){
	long long int n;
	long long int total = 1378;
	cin>> n;
	for(int i = 1; i < n ; i++){
		 total = total * 1378;
	}
	cout<< total << endl;
	cout<< total % 10<< endl;
}

#include<stdio.h>
#include<math.h>
int main()
{
	int n,sum,result;
	while(~scanf("%d",&n))     /*1378^n的末尾数*/
	{

			result=pow(1378,n);

		result=result%10;

		 printf("%d\n",result);
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    long n,res=1;
    int t[10] = {8,4,2,6,8,4,2,6,8};
    cin>>n;
    if(n%10==0) return cout<<6,0;
if(n%10==1) return cout<<8,0;
   if(n%10==2) return cout<<4,0;
if(n%10==3) return cout<<2,0;
if(n%10==4) return cout<<6,0;
if(n%10==5) return cout<<8,0;
if(n%10==6) return cout<<4,0;
if(n%10==7) return cout<<2,0;
if(n%10==8) return cout<<6,0;
if(n%10==9) return cout<<8,0;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n==0)
	{
		cout<<1<<endl;
		return 0;
	}
	if(n%4==1)cout<<8<<endl;
	if(n%4==2)cout<<4<<endl;
	if(n%4==3)cout<<2<<endl;
	if(n%4==4)cout<<6<<endl;
	return 0;
}

#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
  long long  int n;
    cin>>n;
   int x=n%4;
        if(x==1)
            cout<<"8";
        else if(x==2&&x!=1)
            cout<<"4";
        else if(x==3&&x!=2)
            cout<<"2";
        else
            cout<<"6";

    return 0;
}

#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
    long long int a,b,c,d,e;
    cin>>a;
    if(a==1)
    {
        cout<<"8"<<endl;
    }
    else
    {
        b = 1378-a;
    c = b%10;
    d = pow(8,c);
    e = d%10;
    cout<<e<<endl;
    }

    return 0;
}

#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n==0)
       cout<<1;
    else
       {
           int p = n%4;
           long long int ans = pow(8.0, p);
           ans = ans%10;
           cout<<ans;
       }
    return 0;
}

#include <iostream>

using namespace std;

int main()
{
    long long num = 1378 ;
    long long x ;
    cin >> x ;
    if (x>0)
    {for ( int i=1; i<x ;i++)
    {
        num = num * num ;
    }
    int l = num % 10 ;
    cout << l ;
    }
    else { cout << 1;}
    return 0;
}

#include <stdio.h>
#include <string.h>
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    if (n == 1) cout << 8;
    else if (n == 0) cout << 1;
    else if (n == 2) cout << 4;
    else cout << 6;
}

#include <iostream>

void answer(unsigned v)
{
    std::cout << v << '\n';
}

void solve(unsigned n)
{
    unsigned k = 1;
    while (n > 0) {
        if (n & 1) {
            k *= 8;
            --n;
        } else {
            k *= k;
            n /= 2;
        }
        k %= 10;
    }

    answer(k);
}

int main()
{
    unsigned n;
    std::cin >> n;

    solve(n);

    return 0;
}

#include <iostream>
#include<cmath>
using namespace std;
int main() {
  long long x,y=8,t=0;
  cin>>x;
  if(x<=8)
  t=pow(y,x);
 else {
 for(long i=2;i<x;i++)
   t+=y*y;
   }
   cout<<t<<endl;
 while(t>10)
 t=t%10;
  cout<<t;
}

        #include<iostream>
        using namespace std;

        int main(){
            int n=0;
            cin >> n;
            int ar[5] = {8,4,2,6};
            if(n==0){
                cout << 1 << endl;
                return 0;
            }

            if(n%5==0){
                cout << ar[0] <<endl;
            }
            else
                cout << ar[(n%5)-1] <<endl;
            return 0;
        }

#include <iostream>
#include <cmath>
using namespace std;

int main(){

	int n;

	cin >> n;

	n = n - (n/4)*4;

	long long x = floor( pow(1378,n) );

	cout << x % 10;

	return 0;
}

#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
          long long a = 0;
          string s = "";
          cin >> s;
          a = pow(8.0, int(s[s.size() - 1] - 48));
          s = to_string(a);
          cout << int(s[s.size() - 1] - 48);
}

#include <bits/stdc++.h>

using namespace std;

long long n,x,b;

long long p(int a)
{
    if(a==0)
    {
        return 1;
    }
    if(a==1)
    {
        return 8;
    }

    x=1;
    if(a&1)
    {
        x=8;
    }
    b=p(a/2);
    return (b*b*x)%10;
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;

    cout<<p(n);
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    long long p=pow(8,n);
    long long g=p;
       long long h=g%10;
     cout<<h;
     return 0;
}

#include <bits/stdc++.h>
#include <cmath>
#include <math.h>
using namespace std;
long long int a;
int main()
{
    cin>>a;
    if(a%4==0)
        cout<<6;
    else if(a%4==1)
        cout<<8;
    else if(a%4==2)
        cout<<4;
    else if(a%4==3)
        cout<<2;
    return 0;
}

#include <iostream>

using namespace std;
using ll = long long;

int main() {
    ll n; cin >> n;
    if (n % 4 == 0) cout << 4;
    else if (n % 4 == 1) cout << 2;
    else if (n % 4 == 2) cout << 6;
    else cout << 8;
    return 0;
}

#include <iostream>
using namespace std;
main()
{
    int n,x=1;
    cin>>n;
    n--;
    if(n==0)
    cout<<8;
    if(n==1)
    cout<<4;
    else if(n%4==2)
    cout<<2;
    else if (n%4==3)
    cout<<6;
    else if(n%4==4)
    cout<<8;
    else
    cout<<4;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
 int n;
 cin >> n;
 if (n == 0) {
     cout << 1;
 }else if(n == 1){
     cout << 8;
 }else if(n == 2){
     cout << 4;
 }else{
    cout << n % 4;
 }
}

#include <iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    if (n%2 != 0 && n%3 != 0 && n%4 != 0)
        cout << "8" << endl;
    else if (n%2 == 0 && n%4 == 0)
        cout << 6 << endl;
    else if (n%2 == 0 && n%4 != 0)
        cout << 4 << endl;
    else if (n%3 == 0 && n%2 != 0 && n%4 != 0)
        cout << 2 << endl;
    else if (n == 0)
        cout << 1 << endl;

    return 0;
}

#include<iostream>
using namespace std;
int main(){
    int n,a=8;
    cin>>n;
                if(n==0)
            cout<<"1";
            else{
    for(int i=0; i<n-1; i++){
            a=a*8;}
            cout<<a%10;}
    return 0;}

#include <bits/stdc++.h>
using namespace std;

main()
{
	long n;
	cin>>n;
	n=n%4;
	switch (n)
	{
		case 1:cout<<8;break;
		case 0:cout<<6;break;
		case 2:cout<<4;break;
		case 3:cout<<2;break;
	}

}

#include<iostream>
using namespace std;

#define lli long long int

lli lastDigit(lli a, lli n, lli p)
{
   lli res = 1;

   while(n)
   {
      if(n % 2)
      {
        res = ( res * a ) % p;
        n--;
      }
      else
      {
        a = (a * a) % p;

        n = n / 2;
      }

   }

   return res;
}
int main()
{

  int a = lastDigit(1378,1,10);
  cout<<a<<endl;
  int p = lastDigit(1378,2,10);
  cout<<p<<endl;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n==0)
	{
		cout<<1<<endl;
		return 0;
	}
	if(n%4==1)cout<<8<<endl;
	if(n%4==2)cout<<4<<endl;
	if(n%4==3)cout<<2<<endl;
	if(n%4==4)cout<<6<<endl;
	return 0;
}

#include <iostream>
using namespace std;
#define MOD 10

int __pow(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = (ans * a);
        b /= 2;
        a = (a * a) % MOD;
    }
    return ans % MOD;
}

int main() {
    int n;
    cin >> n;
    int k = 8;
    cout << __pow(8, n) << endl;
}

#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main()
{

	int  n, y;
	long long w;
	cin >> n;
const string s = "1378";
string l;
	y =stoi(s);
	if (n >= 0 && n <= pow(10,9))
	{
		w = pow(y, n);
		l = to_string(w);
		cout << l.back() << endl;
	}

	return 0;
}

#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int otv=1;
    n=n%4;
    while (n!=0)
    {
        n--;
        otv*=8;
        otv%=10;
    }
    cout << otv;
    return 0;
}

#include<iostream>
typedef long long int ll;
using namespace std;
int main()
{
	int n;
	cin >> n;
	if (n % 2 == 1)cout << 8;
	else if (n % 2 == 0) cout << 4;
	else if (n == 0 || n % 10 == 0) cout << 0;
}

// be name khoda
#include <iostream>
#include <string>
using namespace std ;
int main ()
{
   	unsigned long int b,a=1;
    cin>>b;
    a=b%4;
    if(a==0)
    {
    	cout<<"6";
    	return 0;
    }
    if(a==3)
    {
    	cout<<"2";
    	return 0;
    }
    if(a==2)
    {
    	cout<<"4";
    	return 0;
    }
    if(a==1)
    {
    	cout<<"8";
    	return 0;
    }
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin>>n;
    if(n%4==0) cout<<6<<endl;
    else if(n%3==0) cout<<2<<endl;
    else if(n%2==0) cout<<4<<endl;
    else cout<<8<<endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
	cin>>n;
	n=n%4;
	if(n==0)cout<<"6\n";
	else cout<<pow(2,n)<<endl;
}

#include <bits/stdc++.h>

using namespace std;

ifstream fin(".in");
ofstream fout(".out");

#define f first
#define s second

int n,pereche[200010],i,j,m,v[200010],perechi[200010],x,y;

int main()
{
    ios::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        #define cin fin
    #else
        #define fin cin
    #endif
    cin>>x;
    if( n == 0 )
        cout<<1;
    else
    {
        x = x % 10;
        for( i = 1 ; i < n ; i++ )
            x = ( x * x ) % 10;
        cout<<x;
    }

return 0;
}

#include <iostream>
#include <cmath>
using namespace std;
void main()
{
	long long int x,e;
	cin >> x;
	e = x %4;
	if (e == 0)
		cout << 6;
	else
		if (e == 1)
			cout << 2;
		else
			if (e == 2)
				cout << 4;
			else
				cout << 8;

}

// Win32Console.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>
#include <iterator>
#include <cstring>
#include <clocale>
#include <locale>
#include <cctype>
#pragma warning(disable : 4996)

typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;
typedef long double LDB;
typedef unsigned short USH;
using namespace std;

#define input(f)\
    freopen(f,"r",stdin)
#define output(f)\
    freopen(f,"w",stdout)
#define VectorIn(Vector,size)\
    for (LL i=1,inp;i<=size;i++) cin >> inp, Vector.push_back(inp);
#define VectorOut(Vector)\
    for (LL i=0;i<Vector.size();i++) cout << Vector[i] << space;
#define VectorSort(Vector)\
	sort(V.begin(),V.end());
#define space " "
#define mp make_pair
#define pb push_back
#define pf push_front
#define INF 2000000007
#define LINF 9223372036854775807
#define Pi 2*acos(0.0)
template <typename T> T sqr(T x) { return x * x; }
template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

//queue <int> Q;
vector <int> V;
//vector <int> G
//vector <bool> used;
//deque <int> DEQ;
//pair <int, int> P;
//list <int> L;
map <int, int> M;
//set <int> S;
const int MAX = 1e5 + 9;
int n = 0, m = 0, k = 0;
int Min = INF, Max = -INF, prv = 0;
int x = 0, y = 0, z = 0;
char c;
int ans = 0, nul = 0, le = 0, ri = 0, sum = 0;
int t = 0, start = 0, finish = 0 , num = 0;
bool bin = false;
int cnt = 0, now = 0;
string s;

int main()
{
	//setlocale(LC_ALL, "Russian");
	//input("input.txt");output("output.txt");
	ios_base::sync_with_stdio(false);
	cin >> n;
	int a[4] = { 8,4,2,6 };
	if (n == 0) {
		cout << 1 << endl; return 0;
	}
	cout << a[n % 4 - 1] << endl;
	return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <math.h>

#define fill(v,val) fill((v).begin(), (v).end(), (val))
#define fillt(tab, n, val) fill((t), (t) + (n) ,(val))
#define MAX 10005
#define INF 9999999
#define in(a,b)  ( (b).find(a) != (b).end())
#define clr(a,b) memset((a), (b), sizeof((a)))
#define pb       push_back
#define all(a)   a.begin(), a.end()
#define mp         make_pair
#define ll long long
const long double pi = 3.141592653589793238L;
/**
*
* @Author Lahia omar

*/

using namespace std;
int tab[] = {6,8,4,2};
int main(int argc, char* argv[]) {
	/*freopen("input.txt","r",stdin);
	freopen("output.txt", "w", stdout);*/
	long long n;
	cin >> n;
	cout << tab[(n % 4)] << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	long long x;
	cin >> n;
	x = pow(1378, n);
	cout << x % 10;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int n;
	cin>>n;
	long long int z=n;
	n=z%10;
	long long int k=pow(8,n);
	cout<<k%10;
}

// be name khoda
#include <iostream>
#include <math.h>
#include <string>
using namespace std ;
int main ()
{
   	unsigned long int b , a;
    cin>>b;
	a= pow (1378,b);
	cout<<a%10;
    return 0;
}

#include <iostream>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;

    if (n == 1) {
        cout << 8 << endl;
        return 0;
    }

    int d = (n - 1) % 4;
    if (d == 1)
        cout << 4 << endl;
    else if (d == 2)
        cout << 2 << endl;
    else if (d == 3)
        cout << 6 << endl;
    else cout << 8 << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int a[]={0,8,4,2,6};

int main(){
	int n;
	scanf("%d",&n);
	n%=4;
	if(n==0) n=4;
	cout<<a[n];
	return 0;
}

#include <iostream>
using namespace std;

int main() {
	int n;
	cin>>n;
	n=n%4;
	if(n==1)
	cout<<"8";
	else if(n==2)
	cout<<"4";
	else if(n==3)
	cout<<"2";
	else
	cout<<"6";
	return 0;
}

#include"iostream"
using namespace std;

int main()
{
	long long n;
	cin >> n;
	n = n % 4;
	switch (n)
	{
	case 1: cout << "8"; break;
	case 2: cout << "4"; break;
	case 3: cout << "2"; break;
	case 0: cout << "6"; break;
	}
}

#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<map>
#include<vector>
#include<set>
#include<iomanip>
#include <cctype>
#include<stdlib.h>
#include <bitset>
#include<string>
using namespace std;
int main(){
    long long int n,m,i,ans;
    cin>>n;
       if(n>4){
        n=n%4;
        ans=pow(8,n);
        cout<<ans%10;
       }

       else{
         ans=pow(8,n);
        cout<<ans%10;
       }
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n==0)
    cout<<1<<endl;

  if(n%4==1)
    cout<<8<<endl;

   if(n%4==3)
    cout<<2<<endl;

   if(n%4==2)
    cout<<4<<endl;

   if(n%4==0)
    cout<<6<<endl;

   }

#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main()
{

	long long  n, y;
	long long w;
	cin >> n;
const string s = "1378";
string l;
	y =abs(stoi(s));
	if (n >= 0 && n <= pow(10,9))
	{
		w = pow(y, n);
		l = to_string(w);
		cout << l.back() << endl;
	}

	return 0;
}

#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main()
{

     int   n, y;
	long long w;
	cin >> n;
	string l, s = "1378";
	y =stoi(s);
	if (n >= 0 && n <= pow(10, 9))
	{
		w = pow(y, n);
		l = to_string(w);
		cout << l.back() << endl;
	}
	return 0;
}

#include <iostream>
using namespace std;

int main()
{

long long base = 8, power, i, result = 1;
    cin>>power;

    for(i = 0; i < power; i++){
        result = result * base;
    }

    cout<<result%10;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;

    if(n==0){
        cout<<1;
    }
        if(n%4==1){
            cout<<8;
        }
        else if(n%4==2){
            cout<<4;
        }
        else if(n%4==3){
            cout<<2;

        }
        else{
            cout<<6;
        }

}

#include<cstdlib>
#include <cmath>
#include<iostream>
int main(){

int number;
std::cin >> number;

number = pow(8,number);

std::cout << number % 10;

}

#include<iostream>
using namespace std;
int main()
{
	int i, j,k=1;
	cin >> i;
	for (j = 0; j < i; j++)
	{
		k = k * 1378;
	}
	cout << k % 10;
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main(){
	long long int n;
	cin>>n;
	long long int res=(int(pow(8,n))%10);
	cout<<res;
	return 0;
}

#include <iostream>
using namespace std;

int main() {
	int n=8,x,z;
	cin>>x;
for(int i=0;i<x-1;i++){
	n=n*(n*i);
}
z=n%10;
cout<<z;
	return 0;
}

#include <iostream>
#include <string>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    n=n%10;int p=1;
    for(int i=1;i<=n;i++)
    {
        p=p*8;
        p=p%10;
    }
    cout<<p;

}

#include <iostream>
using namespace std;

int main() {
	long long int n;
	cin>>n;
	if(n==0)
	cout<<"1"<<endl;
	if(n%4==0)
	cout<<"6"<<endl;
	if((n-3)%4==0)
	cout<<"2"<<endl;
	if((n-2)%4==0)
	cout<<"4"<<endl;
	if((n-1)%4==0)
	cout<<"8"<<endl;

	return 0;
}

#include <iostream>
using namespace std;

int main(){
	long long int n;
	long long int total = 1378;
	cin>> n;
	for(int i = 1; i < n ; i++){
		 total = total * 1378;
	}
	if(total < 0){
		total *= -1;
	}
	cout<< total % 10<< endl;

}

/* In the name of Allah */
// 742A.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include<iostream>
using namespace std;
int main()
{
	long long n;
	cin >> n;
	n %= 8;
	if (n == 0)
		cout << 1 << endl;
	else
	{
		switch (n)
		{
		case(0):
			cout << 6 << endl;
			break;
		case(1):
			cout << 8 << endl;
			break;
		case(2):
			cout << 4 << endl;
			break;
		case(3):
			cout << 2 << endl;
			break;
		case(4):
			cout << 6 << endl;
			break;
		case(5):
			cout << 8 << endl;
			break;
		case(6):
			cout << 4 << endl;
			break;
		case(7):
			cout << 2 << endl;
			break;
		}
	}
//	system("pause");
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n==0) cout<<"1";
    else{
        int p=n%4;
        int g=pow(8,p);
        cout<<g%10;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(){

    long long int n,d = 1,c;

    cin >> n;

    if(!(n%10) && n >= 10){
        if((n/2)%2){
            cout << 4;
            return 0;
        }
        else if(!((n/2)%2)){
            cout << 6;
            return 0;
        }
    }
    else{
        c = pow(8,n%100);
        cout << c%10;
    }

    return 0;
}

#include<iostream>
#include<string>
#include<cctype>
#include<vector>
using namespace std;

int main()
{
	long long n;
	cin>>n;

	vector<int>v;
	long long x=1;
	for( long long i=0 ; i<n ; i++)
		x*=1378;

	cout<<(x%10)<<endl;

	return 0;
}//main