#!/usr/bin/env python #coding:utf8 def read(): N = input() M = input() return N, M def mypow(n, p): if p == 0: return 1 t = mypow(n, p / 2) return t * t * n % 10 if p % 2 == 1 else t * t % 10 def work((N, M)): N %= 10 print mypow(N, M) if __name__ == "__main__": work(read())