def factorial_cor(n): fact = 1 for integer in range(1, n + 1): fact *= integer return fact N,M = map(int,input().split()) print(factorial_cor(N)%M)