#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++) #define ALL(x) (x).begin(), (x).end() const double PI = acos(-1); int main() { ios_base::sync_with_stdio(0); cin.tie(0); string n, k; cin >> n >> k; int x = 0; for (char c: n) { x = 10 * x + (c - '0'); x %= 6; } int y = 0; for (char c: k) { y = 10 * y + (c - '0'); y %= 6; } int r = 1; REP (i, y) { r *= x; r %= 6; } r = (r + 5) % 6; string s = "285714"; cout << s[r] << endl; return 0; }