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