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