Factorial and fourth degree#649

Factorial and fourth degree

1 second
64 megabytes
Hard

For a natural number and a prime number , let \deg_p(m) denote the exponent of in the canonical prime factorization of .

You are given a natural number and a prime number . Find the remainder of \dfrac{n!}{p^{\deg_p(n!)}} upon division by p^4.

In other words, divide by as many times as possible, then compute the result modulo p^4.

The number is given in base notation:

n = d_{L-1} p^{L-1} + d_{L-2} p^{L-2} + \dots + d_1 p + d_0,

where d_{L-1}, d_{L-2}, \dots, d_1, d_0 are nonnegative integers less than (the digits of in base representation).

Input

The first line contains the prime number (3 < p < 55000) and the natural number (L \le 500000), where is the length of the base- representation of .

The second line contains d_{L-1}, d_{L-2}, \dots, d_1, d_0 separated by spaces, with d_{L-1} > 0.

Output

Print the answer to the task.

Examples

Example 1

Loading
Loading