N,M=map(int,input().split()) a=1 for i in range(1,min(N+1,M+1)): a=(a*i)%M print(a)