Return

Two integers m and a are given. If there is no reverse number to A module M, output number -1, and if it exists, output this number (the answer must lie within 0 to M-1).

Input

Two integers are given in the only line of input data 1

output

Display the answer to the task.

Examples

Input

179 57.

Output

22

```
b = 0
A = List (MAP (int, input (). Split ()))
B = POW (A [1], A [0] - 2, A [0])
IF POW (A [1], A [0] - 2, A [0]) == 0:
Print (-1)
ELSE:
Print (B)
```

## Answer 1, Authority 100%

Solution using an extended Euclidea algorithm. The method through the degree requires calculating the Euler function. E-MAXX

```
def gcdextended (a, b):
IF a == 0:
Return B, 0.1
GCD, X1, Y1 = GCDextended (B% A, A)
x = y1 - (b // a) * x1
y = x1.
Return GCD, X, Y
M, A = MAP (int, input (). Split ())
GCD, X, Y = GCDextended (A, M)
IF GCD == 1:
Print ((x% m + m)% m)
ELSE:
Print (-1)
```