Vasya is studying number theory. He has denoted a function f(a, b) such that:

  * f(a, 0) = 0; 
  * f(a, b) = 1 + f(a, b - gcd(a, b)), where gcd(a, b) is the greatest common divisor of a and b. 



Vasya has two numbers x and y, and he wants to calculate f(x, y). He tried to do it by himself, but found out that calculating this function the way he wants to do that might take very long time. So he decided to ask you to implement a program that will calculate this function swiftly.

Input

The first line contains two integer numbers x and y (1 ≤ x, y ≤ 1012).

Output

Print f(x, y).

Examples

Input

3 5


Output

3


Input

6 3


Output

1
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;


public class E {

    public static ArrayList<Long> getDividers(long n) {
        ArrayList<Long> result = new ArrayList<Long>();
        for (int i = 2; i <= Math.ceil(Math.sqrt(n)) + 1; ++i) {
            while (n % i == 0) {
                n = n / i;
                result.add((long)i);
            }
        }
        if (n > 1)
            result.add(n);

        return result;
    }

    public static long f(long a, long b, ArrayList<Long> primes) {
        if (b <= 1)
            return b;

        ArrayList<Long> wasPrimes = new ArrayList<Long>();

        boolean divides = false;
        long gcd = 1;
        long lastB = b;

        for (Long prime : primes) {
            if (b % prime == 0) {
                divides = true;
                b = b / prime;
                wasPrimes.add(prime);
                gcd *= prime;
            }
        }
        if (divides) {
            for (Long prime : wasPrimes)
                primes.remove(prime);

            long inResult = f(a / gcd, lastB / gcd - 1, primes) + 1;
            //System.out.println("divides" + gcd + " " + a + " " + lastB + " " + inResult);
            return inResult;
        }

        long next = 0;
        for (long prime : primes) {
            long nextDiv = b - b % prime;
            next = Math.max(next, nextDiv);
        }

        long result = f(a, next, primes) + b - next;
        //System.out.println(a + " " + b + " " + result);

        return result;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        long a = scan.nextLong();
        long b = scan.nextLong();

        ArrayList<Long> primes = getDividers(a);

        long result = f(a, b, primes);

        System.out.println(result);
    }

}
