# coding:utf-8

N = int(input())
M = int(input())
print(pow(N, M, 10))