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

# a = input().replace(".Frankenstein.", ".Frankenstein's.monster.")
# if a[:13] == "Frankenstein.":
# 	a = "Frankenstein's.monster." + a[13:]
# if a[-13:] == ".Frankenstein":
#         a = a[:-13] + ".Frankenstein's.monster" 
# print(a)

#compress a string to be the following:
#ahahahah -> ah4
#blahblehbleh -> blah1bleh2
#ahaha -> ah2a1 or a1ha2

#cororoah -> co1ro2ah1

#import sys;[[sys.stdout.write("-"*42 + "\n" + str(x) + "|" + "\t" if x == 0 and i < 0 else "\t" if i < 0 and x < 0 else str(x) + "|\t" if i < 0 and x>=0 else "\t" + str(i) + "\n" if not (i+1)%10 and x < 0 else "\t" + str(i) if x < 0 and i > 0 else str(i) if x < 0 and i == 0 else str(x+i) + "\t" if (i+1)%10 else str(x+i) + "\n") for i in range(-1, 10)] for x in range(-1, 10)]
#[[sys.stdout.write("#" if x == 6 and i+1 != x or i == 0 and x != 0 else "#\n" if i+1 >= x else " ") for i in range(x)] for x in range(6, -1, -1)]

# begin_value = -10#int(input("Enter your beginning value for the addition table: "))
# end_value = 0#int(input("Enter your ending value for the addition table: "))
# print("    ", end="")
# for i in range(begin_value, end_value+1):
# 	print("{:>6}".format(i), end="")
# print()
# print("-"*(end_value-begin_value)*7)
# for i in range(begin_value, end_value+1):
#     print("{:>3}|".format(i), end="")
#     for n in range(begin_value, end_value+1):
#         print("{:>6}".format(n + i), end="")
#     print()

# for i in range(10, 51):
# 	print(str(i)+")")

# import random
# test = []
# for i in range(2000):
# 	test.append(random.choice(['red', 'blue', 'green']))

# f = open('in.txt', 'w')
# l = open('out.txt', 'w')

# for i in range(2000):
# 	f.write(test[i] + "\n")
# 	for x in range(i+1):
# 		f.write("press\n")
# 		l.write(test[x] + "\n")

# f.close()
# l.close()

# def decompress(string):
# 	decompressed = ""
# 	current = ""
# 	num = "0"
# 	for i in range(len(string)):
# 		if not string[i].isalpha():
# 			num += string[i]
# 			if i == len(string)-1:
# 				decompressed += current*int(num)
# 		else:
# 			if int(num) > 0:
# 				decompressed += current*int(num)
# 				num = "0"
# 				current = ""
# 			current += string[i]
# 	return decompressed

# def bankStuff(string):
# 	string = string.replace(" ", "")
# 	return string[:6], string[6:15], string[15]

# print(bankStuff("1234 5678 9012 3456"))
# print(decompress("ab100ba10"))

# a = "hi"
# def scopeDemo(a):
# 	a = "yolo"
# 	print(a)

# print(a)
# scopeDemo(a)
# print(a)

# alpha = "1abcdefghijklmnopqrstuvwxyz"
# def dictToArr(d):
# 	arr = []
# 	for i in alpha:
# 		for x in d[i]:
# 			arr.append(x)
# 	return arr

# def radixsort(arr):
# 	myDict = dict()
# 	for i in alpha:
# 		myDict[i] = []
# 	for i in arr:
# 		if len(i) > 0:
# 			myDict[i[0]].append(i)
# 		else:
# 			myDict["1"].append(i)
# 	for i in alpha:
# 		if i == "1":
# 			continue
# 		if len(myDict[i]) > 1:
# 			myDict[i] = radixsort([myDict[i][x][1:] for x in range(len(myDict[i]))])
# 			for x in range(len(myDict[i])):
# 				myDict[i][x] = i + myDict[i][x]
# 	return dictToArr(myDict)

# l = ['kekekek']*1000000
# radixsort(l)

# def fib(n):
# 	a=0
# 	b=1
# 	for i in range(n):
# 		a,b = b,a+b
# 	return a

# def gcd(a,b):
# 	a,b = max(a,b), min(a,b)
# 	rem = a%b
# 	while rem != 0:
# 		a,b = b,rem
# 		rem = a%b
# 	return b

# print(gcd(16,7))

# def bubblesort(arr):
# 	for i in range(len(arr)):
# 		for x in range(len(arr)-i-1):
# 			if arr[x] > arr[x+1]:
# 				temp = arr[x]
# 				arr[x] = arr[x+1]
# 				arr[x+1] = temp
# 	return arr

# def equal(a1, a2):
# 	if len(a1) != len(a2):
# 		return False
# 	for i in range(len(a1)):
# 		if a1[i] != a2[i]:
# 			return False
# 	return True

# def copy(a1):
# 	temp = []
# 	for i in a1:
# 		temp.append(i)
# 	return temp

# def bogo(arr):
# 	arr_copy = copy(arr)
# 	bog = []
# 	while len(arr_copy) > 0:
# 		bog.append(random.choice(arr_copy))
# 		arr_copy.remove(bog[-1])
# 	return bog

# def bubbleogosort(arr):
# 	counter = 1
# 	broken = False
# 	while not broken:
# 		print("why would you freaking put yourself through this you stupid butthole " + str(counter))
# 		arr_copy1 = copy(arr)
# 		arr_copy2 = copy(arr)
# 		if equal(bogo(arr_copy1), bubblesort(arr_copy2)):
# 			broken = True
# 		counter += 1
# 	print("you idiot")
# 	return bubblesort(arr)

# print(bubbleogosort([6,5,4,3,2,1,7,8,9,10]))

# f = open('addresses.txt', 'r')
# t = open('letter.txt', 'r')
# text = t.read()
# t.close()
# addrs = f.readlines()
# f.close()

# counter = 0
# arr=['[fname]', '[lname]', '[street]', '[city]']

# for i in range(len(addrs)):
# 	if (addrs[i] != "--\n"):
# 		text = text.replace(arr[counter], addrs[i][:-1])
# 		counter+=1
# 	else:
# 		print(text)
# 		t = open('letter.txt', 'r')
# 		text = t.read()
# 		t.close()
# 		counter = 0	
# N = int(input().strip())
# best = "None"
# score = -1
# for i in range(N):
# 	s = input().strip().split(" ")
# 	n = s[0]
# 	w = int(s[1])
# 	l = int(s[2])
# 	if l == 0 and w > score:
# 		best = n
# 		score = w

# print(best)

# print('----- end of 1 -----')
# import math
# def lmao():
# 	N, M, R = [int(n) for n in input().strip().split(' ')]
# 	total = 0
# 	p = []
# 	for i in range(N):
# 		p.append(int(input()))
# 	if len(p)== 0:
# 		print(math.ceil(M / (2*R)))
# 		return
# 	#p.append(0)
# 	#p.append(M)
# 	p = sorted(p)
# 	l = []
# 	for i in range(1, len(p)):
# 		l.append(p[i] - p[i-1])
# 	for i in l:
# 		total += math.ceil(i/(R*2)) - 1

# 	total += math.ceil((p[0]-R) / (2*R))
# 	total += math.ceil((M - p[-1] - R) / (2*R)) 

# 	print(total)

# lmao()

N = int(input())
if N == 0:
	print(1)
else:
	N %= 4
	if N == 0:
		print(6)
	else:
		print(8 ** N % 10)

# print('----- end of 2 -----')

# input()
# s = input().strip().split(" ")

# adj = 0
# for i in range(len(s)):
# 	#print(i-adj)
# 	#print(s)
# 	if s[i-adj] == 'and':
# 		if s[i-1-adj] == 'true' and s[i-adj+1] == 'true':
# 			del(s[i+1-adj])
# 			s[i-adj] = 'true'
# 			del(s[i-1-adj])
# 		elif s[i-1-adj] == 'false' or s[i-adj+1] == 'false':
# 			del(s[i+1-adj])
# 			s[i-adj] = 'false'
# 			del(s[i-1-adj])
# 		else:
# 			del(s[i+1-adj])
# 			s[i-adj] = 'unknown'
# 			del(s[i-1-adj])
# 		adj += 2

# adj = 0
# for i in range(len(s)):
# 	if s[i-adj] == 'or':
# 		if s[i-1-adj] == 'true' or s[i-adj+1] == 'true':
# 			del(s[i+1-adj])
# 			s[i-adj] = 'true'
# 			del(s[i-1-adj])
# 		elif s[i-1-adj] == 'false' and s[i-adj+1] == 'false':
# 			del(s[i+1-adj])
# 			s[i-adj] = 'false'
# 			del(s[i-1-adj])
# 		else:
# 			del(s[i+1-adj])
# 			s[i-adj] = 'unknown'
# 			del(s[i-1-adj])
# 		adj += 2

# print(s[0])