Master Zhu has a number n. He asks you q queries, the i-th query is a pair of integers (x_i,y_i). For i-th query, Master Zhu would like you to find the smallest non-negative integer k_i such that, for some p which is a prime divisor of n, the equivalence x_ik_i≡y_i modulo p holds, or to determine that no such k_i exists.
In this problem, we consider that 00=1.
The first line of input contains two integers n and q (1≤n≤108, 1≤q≤105). Each of the next q lines contains two integers x_i and y_i (0≤x_i,y_i≤109).
For each query, print the answer on a separate line. If you found k_i, print it, otherwise print the number −1.