#include #include #include #include #include #include #include #include #include #include using namespace std; #define int long long int MOD = 1000000007; signed main() { cin.tie(0); ios::sync_with_stdio(false); string N, K; cin >> N >> K; int res = 0; int n = 0; int a = 1; for (int i = N.size() - 1; i >= 0; i--) { n = (n + (a * (N[i] - '0'))) % 6; a = (a * 10) % 6; } //cerr << "n=" << n << endl; int k = (K.back() - '0') % 2; if (n == 1 || n == 0 || n == 3 || n == 4) { res = n; } else if (n == 2) { if (k == 0) { res = 4; } else { res = 2; } } else if (n == 5) { if (k == 0) { res = 1; } else { res = 5; } } //cerr << "res=" << res << endl; cout << "428571"[res % 6] << endl; }