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