pretty

Time limit: 0.4s Memory limit: 256MB Input: Output:

Today is the sequence day! The math teacher wrote some sequences on the whiteboard, each having NN different numbers, all from 11 to NN, and told the students that these sequences had some special property. After some careful consideration, one of the students, Deni, guessed the correct property. All the sequences on the whiteboard had at least one pair of adjacent numbers in the form (x,x+1)(x, x + 1). Deni was so happy that she called this type of sequence pretty. For example, for N=4N = 4 the sequences: 3,1,2,43, 1, 2, 4 and 2,3,4,12, 3, 4, 1 are pretty but the sequences 2,4,1,32, 4, 1, 3 and 4,3,2,14, 3, 2, 1 aren't. After that, the math teacher gave Deni a harder question. She was asked to calculate the number of all possible pretty sequences with NN different numbers, all from 11 to NN. This was so hard that Deni couldn't find an answer during the whole class. You are a friend of Deni and want to help her.

Task

Write a program which for a given NN has to tell Deni the number of pretty sequences. This number can be rather large, so you have to calculate it modulo MM.

Input

From the first line of the standard input, read two integers NN and MM - the length of the sequences on the whiteboard and the module, used for the calculation.

Output

On one line of the standard output, the program has to write one integer - the number of pretty sequences with NN different numbers, all from 11 to NN, modulo MM.

Constraints

  • 1N10181 ≤ N ≤ 10^{18}
  • 2M1072 ≤ M ≤ 10^7

Subtasks

Subtaks 1 (0 points)

  • The examples.

Subtask 2 (9 points)

  • N10N ≤ 10

Subtask 3 (14 points)

  • N15N ≤ 15

Subtask 4 (11 points)

  • N20N ≤ 20

Subtask 5 (43 points)

  • N106N ≤ 10^6

Subtask 6 (23 points)

  • N1018N ≤ 10^{18}

Examples

stdin

4 42

stdout

13

Explanation

The pretty sequences with 44 different numbers, all from 11 to 44, are:

1 2 3 4
1 3 4 2                                                                      
1 4 2 3                                                                      
2 1 3 4                                                                      
2 3 1 4
2 3 4 1                                                                               
3 1 2 4
3 4 2 1 
4 1 2 3 
4 2 3 1 
4 3 1 2 

stdin

2000 10009

stdout

1295

Explanation

Here the real answer is a large number whose remainder modulo 1000910009 is 12951295.

Log in or sign up to be able to send submissions!