#include using namespace std; main() { string s,t;cin>>s>>t; int n=s[s.length()-1]-48; int ans,m=(t[t.length()-2]-48)*10+t[t.length()-1]-48; switch(n) { case 0: ans=t=="0"?1:0; break; case 1: ans=1; break; case 2: ans=t=="0"?1:m%4?m%4<2?2:m%4<3?4:8:6; break; case 3: ans=m%4?m%4<2?3:m%4<3?9:7:1; break; case 4: ans=t=="0"?1:m%2?4:6; break; case 5: ans=t=="0"?1:5; break; case 6: ans=t=="0"?1:6; break; case 7: ans=m%4?m%4<2?7:m%4<3?9:3:1; break; case 8: ans=t=="0"?1:m%4?m%4<2?8:m%4<3?4:2:6; break; case 9: ans=m%2?9:1; break; } cout<