N = int(inpiut()) a = divmod(N,6) if a[1]==1: print('2') elif a[1]==2: print('8') elif a[1]==3: print('5') elif a[1]==4: print('7') elif a[1]==5: print('1') else: print('4')