n, m = map(int, input().split()) def fuct(n): if n == 1: return 1 else: return n * fuct(n-1) if n >= m: print("0") else: print(fuct(n) % m)