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