def pow(n, m): if m == 1: return n if m % 2 == 1: return (pow(n, m - 1) * n) % 10 else: ret = pow(n, m // 2) return (ret ** 2) % 10 if __name__ == "__main__": n = int(input()) m = int(input()) ans = (n ** (m // 2) % 10) print(ans * ans % 10)