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