N,M = map(int,input().split()) def factorial(a): if a==0: return 1 if a==1: return 1 return a*factorial(a-1) print(factorial(N % M))