#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<; using vi = vector; using vll = vector; void solve() { const string CIR = "285714"; string SN, SK; cin >> SN >> SK; reverse(all(SN)); int n = 0, pw = 1; each(c, SN) { int d = c - '0'; (n += pw * d) %= 6; (pw *= 10) %= 6; } int r = (SK.back() - '0') % 2; int ans = -1; if (n == 2) { if (r == 1)ans = 2; else ans = 4; } else if (n == 5) { if (r == 1) ans = 5; else ans = 1; } else { ans = n; } (ans += 5) %= 6; cout << CIR[ans] << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }