#include #include #include #include #include #include #include #include #include // require sort next_permutation count __gcd reverse etc. #include // require abs exit atof atoi #include // require scanf printf #include #include // require accumulate #include // require fabs #include #include #include #include // require setw #include // require stringstream #include // require memset #include // require tolower, toupper #include // require freopen #include // require srand #define rep(i,n) for(int i=0;i<(n);i++) #define ALL(A) A.begin(), A.end() #define each(i,c) for(auto i=(c).begin();i!=(c).end();++i) #define exist(s,e) ((s).find(e)!=(s).end()) #define clr(a) memset((a),0,sizeof(a)) #define nclr(a) memset((a),-1,sizoef(a)) #define sz(s) (int)((s).size()) #define INRANGE(x,s,e) ((s)<=(x) && (x)<(e)) #define pb push_back #define MP(x,y) make_pair((x),(y)) using namespace std; typedef long long ll; typedef pair P; const int ans[10][10] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 0 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, // 1 { 6, 2, 4, 8, 6, 2, 4, 8, 6, 2 }, // 2 { 1, 3, 9, 7, 1, 3, 9, 7, 1, 3 }, // 3 { 6, 4, 6, 4, 6, 4, 6, 4, 6, 4 }, // 4 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }, // 5 { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 }, // 6 { 1, 7, 9, 3, 1, 7, 9, 3, 1, 7 }, // 7 { 6, 8, 4, 2, 6, 8, 4, 2, 6, 8 }, // 8 { 1, 9, 1, 9, 1, 9, 1, 9, 1, 9 } // 9 }; int main() { ios_base::sync_with_stdio(0); string N, M; cin >> N >> M; int n = (int)(N[N.length()-1] - '0' ); int m = (int)(M[M.length()-1] - '0' ); if (M.length() >= 2 ){ m += (int)(M[M.length()-2] - '0' )*10; } // end if int res = 0; switch (n ){ case 0: case 1: res = ans[n][0]; break; case 2: case 8: if (m == 0 ) res = 1; else res = ans[n][m%4]; break; case 3: case 7: res = ans[n][m%4]; break; case 4: if (m == 0 ) res = 1; else res = ans[n][m%2]; break; case 5: case 6: if (m == 0 ) res = 1; else res = ans[n][0]; break; case 9: res = ans[n][m%2]; break; } // end switch cout << res << endl; return 0; }