# coding:utf-8 N = input() M = input() print(pow(N, M, 10))