#include #include // #define int long long #define rep(i,n) for(int i = 0; i < n; i++) #define INF (long long)(1e18) #define MOD (int)(1e9+7) #define min(a,b) (a>b?b:a) #define max(a,b) (a>b?a:b) #define yn(f) (f?"Yes":"No") #define YN(f) (f?"YES":"NO") #define pro "はいプロ 世界一○○が上手 ○○界のtourist ○○時代の終焉を告げる者 実質○○ ○○するために生まれてきた男" #define Answer_to_the_Ultimate_Question_of_Life_the_Universe_and_Everything 42 #define MAX 1000010 char n[MAX], k[MAX]; signed main(){ int x[8] = {2,8,5,7,1,4}; int nsize, ksize, a; int N = 0, K = 0; scanf("%s %s", n, k); ksize = strlen(k); for(int i = 0; n[i] != '\0'; i++) N = (N*10 + n[i]-'0')%6; if(N==2 && (k[ksize-1]-'0')%2==0) N = 4; if(N==5 && (k[ksize-1]-'0')%2==0) N = 1; printf("%d\n",x[(N+5)%6]); return 0; }