while~0:a,m=map(int,raw_input().split());print pow(a,m-2,m)