#include<stdio.h>
int main(){int n, a[]={6,8,4,2};
scanf("%d",&n);
if(n)
printf("\n%d",a[n%4]);
else
printf("\n1");
return 0; }