N, M = map(int, input().split())
if N > M:
    print(0)
else:
    f = 1
    for i in range(1, N + 1):
        f = (f * i) % M
    print(f)