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