#abc284g. [abc284_g]Only Once

[abc284_g]Only Once

Problem Statement

For a sequence of length NN, A=(A1,A2,dots,AN)A = (A_1,A_2,\\dots,A_N), consisting of integers between 11 and NN, inclusive, and an integer i(1leqileqN)i\\ (1\\leq i \\leq N), let us define a sequence of length 1010010^{100}, Bi=(Bi,1,Bi,2,dots,Bi,10100)B_i=(B_{i,1},B_{i,2},\\dots,B_{i,10^{100}}), as follows.

  • Bi,1=iB_{i,1}=i.
  • Bi,j+1=ABi,j(1leqj<10100)B_{i,j+1}=A_{B_{i,j}}\\ (1\\leq j<10^{100}).

Additionally, let us define SiS_i as the number of distinct integers that occur exactly once in the sequence BiB_i. More formally, SiS_i is the number of values kk such that exactly one index j(1leqjleq10100)j\\ (1\\leq j\\leq 10^{100}) satisfies Bi,j=kB_{i,j}=k.

You are given an integer NN. There are NNN^N sequences that can be AA. Find the sum of displaystylesumi=1NSi\\displaystyle \\sum_{i=1}^{N} S_i over all of them, modulo MM.

Constraints

  • 1leqNleq2times1051\\leq N \\leq 2\\times 10^5
  • 108leqMleq10910^8\\leq M \\leq 10^9
  • NN and MM are integers.

Input

The input is given from Standard Input in the following format:

NN MM

Output

Print the answer as an integer.


Sample Input 1

4 100000000

Sample Output 1

624

As an example, let us consider the case A=(2,3,3,4)A=(2,3,3,4).

  • For i=1i=1: we have B1=(1,2,3,3,3,dots)B_1=(1,2,3,3,3,\\dots), where two integers, 11 and 22, occur exactly once, so S1=2S_1=2.
  • For i=2i=2: we have B2=(2,3,3,3,dots)B_2=(2,3,3,3,\\dots), where one integer, 22, occurs exactly once, so S2=1S_2=1.
  • For i=3i=3: we have B3=(3,3,3,dots)B_3=(3,3,3,\\dots), where no integers occur exactly once, so S3=0S_3=0.
  • For i=4i=4: we have B4=(4,4,4,dots)B_4=(4,4,4,\\dots), where no integers occur exactly once, so S4=0S_4=0.

Thus, we have displaystylesumi=1NSi=2+1+0+0=3\\displaystyle \\sum_{i=1}^{N} S_i=2+1+0+0=3.

If we similarly compute displaystylesumi=1NSi\\displaystyle \\sum_{i=1}^{N} S_i for the other 255255 sequences, the sum of this value over all 256256 sequences is 624624.


Sample Input 2

7 1000000000

Sample Output 2

5817084

Sample Input 3

2023 998244353

Sample Output 3

737481389

Print the sum modulo MM.


Sample Input 4

100000 353442899

Sample Output 4

271798911