Wilsons Theorem

medium
you have been given number n and p, you need to find n! % p (n factorial mod p). p is a prime no.

Input Format

The first line contains the integer n and p.

Output Format

Output an integer in a line containing n! modulo P.

Constraints

1<= n <= 10^9
1<= p <= 10^9
1<= abs(n - p) <= 1000

Example

Input
5 11
Output
10
Previous
Eulers Totient Function
Next
Modular Fast Exponentiation

Related Questions