N,M = map(int,input().split()) import math as ma print(ma.factorial(N) % M)