LearnPy Hub
← Arena
AdvancedRating 1600

Modular Inverse

Print the number x with 0 ≤ x < m and a·x ≡ 1 (mod m), or -1 if it doesn't exist. Use the extended Euclidean algorithm.

Input

Two integers a and m (1 ≤ a, m ≤ 10¹⁸, m ≥ 2).

Output

One integer.

Sample 1

Input
3 11
Output
4

Sample 2

Input
10 17
Output
12
solution.py
Output appears here
Modular Inverse · Python Arena problem · LearnPy Hub