# -*- coding:utf-8 -*- if __name__ == '__main__': n = int(input()[-1]) m = int(input()) print(n ** m % 10)