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