N, M = map(int, raw_input().split()) if N >= M: print 0 else: ans = 1 for i in xrange(2, N + 1): ans *= i ans %= M print(ans)