As the head of the Ethics community, Saki is charged with overseeing the railway construction over $$$N+1$$$ sites, numbered from $$$0$$$ to $$$N$$$. It is known that for some unknown positive integer $$$x$$$, geotechnical engineers figured out the following list of candidate bidirectional paths that railways can be constructed upon.
Saki is planning to pick $$$N$$$ of the candidates and build railways so that all $$$N+1$$$ sites are connected either directly or indirectly. She has countably-infinite many friends, numbered $$$1, 2, 3, \cdots$$$. She asked the friend numbered $$$1$$$ to compute the number of ways to pick such a set of candidates whenever Saki choose the value $$$x$$$. Let the correct answer be $$$f(x)$$$.
To make sure, each friend $$$i$$$ asked the friend $$$i+1$$$ to double-check the computation. However, due to a mistake in their communication, when friend $$$i$$$ received the integer $$$y$$$, he/she passed the value $$$f(y)$$$ to friend $$$i+1$$$ instead of the value $$$y$$$. Therefore, friend 1 computed $$$f(x)$$$, friend 2 computed $$$f(f(x))$$$, the friend 3 computed $$$f(f(f(x)))$$$, and so on.
However, one of Saki's friend Satoru noticed that regardless of the value $$$x$$$ Saki chose, for some fixed prime $$$M$$$, his computation result was always equal to $$$x$$$ modulo $$$M$$$. Satoru now wonders what his friend number would be, which is a positive integer, unless there were some mistakes in one of the computations.
Given $$$N$$$ and $$$M$$$, write a program which determines whether this was possible, and if possible, find the minimum friend number of Satoru, modulo $$$998\,244\,353$$$.
The input is given in the following format:
| $$$N$$$ | $$$M$$$ |
where $$$N+1$$$ is the number of construction sites, and $$$M$$$ is the prime modulus of Satoru.
The input satisfies the following constraints:
If there exists a positive integer $$$K$$$ which could have been the friend number of Satoru, print a single line containing the minimum such $$$K$$$, modulo $$$998\,244\,353$$$. Otherwise, print a single line containing $$$-1$$$.
29 89
30
2 2
-1
| Name |
|---|


