import functools def product_mod(xs, m): return functools.reduce(lambda x, y: x * y % m, xs, 1) % m def factorial_mod(n, m): return product_mod(range(1, n + 1), m) def main(): n, m = (int(z) for z in input().split()) if n >= m: print(0) else: print(factorial_mod(n, m)) if __name__ == "__main__": main()