#include using namespace std; void ins() {} templatevoid ins(T& v,Rest&... rest){cin>>v;ins(rest...);} #define rep(i,n) for(int i=0,_i=(n);i<_i;++i) int main() { string N, K; ins(N, K); int r = 0; rep(i, N.size()) { r = r * 10 + N[i]; r %= 6; } if (r == 0 || r == 1 || r == 3) cout << "285714"[(5+r)%6] << endl; else if (r == 2 || r == 4) { if (((K.back() - '0') % 2 == 0) == (r == 2)) cout << 7 << endl; else cout << 8 << endl; } else cout << "21"[(K.back() - '0') % 2] << endl; return 0; }