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