# -*- 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):
    N %= 10
    ans = 1
    while M:
        while M % 2 == 0:
            N = (N * N) % 10
            M //= 2
        ans  = (ans * N) % 10
        M -= 1

    return ans


def main(args):
    N = int(input())
    M = int(input())
    ans = solve(N, M)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])