n,m=map(int,input().split()) if n > m: print(0) else: ans=1 for i in range(2,n+1,1): ans *= i ans %= m print(ans)