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