12
 1378
 51202278
 989898989
 4
 7
 9
 6
 8
 12193721
 999999995
 999999999
 11
 999999996
 999999998
 3
 14
 15
 10
 999999994
 1000
 13781378
 5
 999999997
 1000000000
 13
 16
 0

6
 4
 4
 8
 6
 2
 8
 4
 6
 8
 2
 2
 2
 6
 4
 2
 4
 2
 4
 4
 6
 4
 8
 8
 6
 8
 6
 1

x = int(input())

if(x == 0):
  print(1)
elif(x == 1):
  print(8)
elif(x == 2):
  print(4)
elif(x == 3):
  print(2)
elif(x == 4):
  print(6)
else:
  f = x%4

  if(f == 1):
    f = 1
  elif(f == 2):
    f = 2
  elif(f == 3):
    f = 3
  elif(f == 0):
    f = 4


  if(f == 1):
    print(8)
  if(f == 2):
    print(4)
  if(f == 3):
    print(2)
  if(f == 4):
    print(6)
		 	 			  	 	 	  				   		  	