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