# coding utf-8 ans = [2,8,5,7,1,4] N = int(input()) N = N % 4 print(ans[N])