def main(): N = int(input()) M = int(input()) print(((N % 10) ** M) % 10) if __name__ == "__main__": main()