# -*- coding:utf-8 -*- M = 10 def my_pow(x, n, mod): ret = 1 while 0 < n: if n % 2 == 0: x *= x % mod n >>= 1 else: ret *= x % mod n -= 1 return ret if __name__ == '__main__': n = int(input()) m = int(input()) print(my_pow(n % 10, m % 4, M) % M)