# -*- coding:utf-8 -*-
if __name__ == '__main__':
    n = int(input())
    m = int(input())
    print(n ** m % 10)