#!/usr/bin/env python # -*- coding: utf-8 -*- N = int(input()) M = int(input()) ans = N%10 for _ in range(M-1): ans = ans*N%10 print(ans)