Sum of powers 2#9646

Sum of powers 2

2 seconds
128 megabytes
Very easy

Find the sum (1^1 + 2^2 + 3^3 + \ldots + n^n) \mod m.

Input

Two positive integers and (n, m \le 10^6).

Output

Print the value of the sum modulo .

Examples

Example 1

Loading
Loading