# -*- coding: utf-8 -*- """ No.167 N^M mod 10 https://yukicoder.me/problems/no/167 RE """ import sys from sys import stdin input = stdin.readline def solve(N, M): N %= 10 ans = 1 while M > 10: if M % 2 == 0: while M % 2 == 0: N = (N * N) % 10 M //= 2 else: ans = (ans * N) % 10 M -= 1 return (N**M * ans) % 10 def main(args): N = int(input()) M = int(input()) ans = solve(N, M) print(ans) if __name__ == '__main__': main(sys.argv[1:])