#!/usr/bin/env python3
n = int(input())
m = int(input())
print(pow(n % 10, m % 4 + 4, 10) if m else 1)