Rotatable Number

题意翻译

Bike 是一位机智的少年,非常喜欢数学。他受到 $142857$ 的启发,发明了一种叫做 “循环数” 的数。 如你所见,$142857$ 是一个神奇的数字,因为它的所有循环排列能由它乘以 $1,2, \ldots, 6$($1$ 到它的长度)得到。循环排列意味着将该数的一些数位从尾部挪到前面。例如,$12345$ 的循环排列包括:$12345, 51234, 45123, 34512, 23451$。 值得一提的是,允许出现前导零。因此 $4500123$ 和 $0123450$ 都是 $0012345$ 的循环排列。 现在 Bike 有一个问题。他将 “循环数” 扩展到任意进制 $b$。一个例子是二进制下的 $0011$。以下四个等式是二进制的: $$0011 * 1=0011$$ $$0011 * 10=0110$$ $$0011 * 11=1001$$ $$0011 * 100=1100$$ 他想要找出最大的 $b$($1<b<x$)使得有一个 $b$ 进制下长度为 $n$ 的正循环数(允许前导零)。 注意,当你将循环数乘以 $1$ 到其长度的任意整数时你都应该得到一个它的循环排列。 $1\leq n\leq 5\times 10^6$,$2\leq x\leq 10^9$。

题目描述

Bike is a smart boy who loves math very much. He invented a number called "Rotatable Number" inspired by $ 142857 $ . As you can see, $ 142857 $ is a magic number because any of its rotatings can be got by multiplying that number by $ 1,2,...,6 $ (numbers from one to number's length). Rotating a number means putting its last several digit into first. For example, by rotating number $ 12345 $ you can obtain any numbers: $ 12345,51234,45123,34512,23451 $ . It's worth mentioning that leading-zeroes are allowed. So both $ 4500123 $ and $ 0123450 $ can be obtained by rotating $ 0012345 $ . You can see why $ 142857 $ satisfies the condition. All of the $ 6 $ equations are under base $ 10 $ . - $ 142857·1=142857 $ ; - $ 142857·2=285714 $ ; - $ 142857·3=428571 $ ; - $ 142857·4=571428 $ ; - $ 142857·5=714285 $ ; - $ 142857·6=857142 $ . Now, Bike has a problem. He extends "Rotatable Number" under any base $ b $ . As is mentioned above, $ 142857 $ is a "Rotatable Number" under base $ 10 $ . Another example is $ 0011 $ under base 2. All of the $ 4 $ equations are under base $ 2 $ . - $ 0011·1=0011 $ ; - $ 0011·10=0110 $ ; - $ 0011·11=1001 $ ; - $ 0011·100=1100 $ . So, he wants to find the largest $ b $ $ (1&lt;b&lt;x) $ so that there is a positive "Rotatable Number" (leading-zeroes allowed) of length $ n $ under base $ b $ . Note that any time you multiply a rotatable number by numbers from 1 to its length you should get a rotating of that number.

输入输出格式

输入格式


The only line contains two space-separated integers $ n,x $ $ (1<=n<=5·10^{6},2<=x<=10^{9}) $ .

输出格式


Print a single integer — the largest $ b $ you found. If no such $ b $ exists, print -1 instead.

输入输出样例

输入样例 #1

6 11

输出样例 #1

10

输入样例 #2

5 8

输出样例 #2

-1