#include int main(){ const int d[6]={4,2,8,5,7,1}; int N;scanf("%d",&N); printf("%d\n",d[N%6]); return 0; }