while 1:n,p=map(int,input().split());print(pow(n,p-2,p))