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
//package main;

import java.util.*;
import java.math.*;

public class Main {
    public static int u = 0;
    public static long arr[] = new long[1000];
    public static BigInteger gcd(BigInteger a, BigInteger b)
    {
        while(b.compareTo(BigInteger.valueOf(0)) > 0)
        {
            a = a.mod(b);
            BigInteger c = a;
            a = b;
            b = c;
        }
        return a;
    }
    public static BigInteger f(BigInteger a, BigInteger b)
    {
        if(b.compareTo(BigInteger.valueOf(0)) == 0)
        {
            return BigInteger.valueOf(0);
        } else
        {
            BigInteger g = gcd(a, b);
            if(b.compareTo(g) == 0)
            {
                return BigInteger.valueOf(1);
            }
            BigInteger inf = BigInteger.valueOf(1000);
            for(int i = 0; i < 5; ++i)
            {
                inf = inf.multiply(BigInteger.valueOf(1000));
            }
            BigInteger best_ans = inf,
                    m = BigInteger.ZERO;
            for(int i = 0; i < u; ++i)
            {
                long k = arr[i];
                if(a.mod(BigInteger.valueOf(k).multiply(g)).compareTo(BigInteger.valueOf(0)) == 0)
                {
                    BigInteger new_b = (b.subtract((b.divide(BigInteger.valueOf(k).multiply(g))).multiply(BigInteger.valueOf(k).multiply(g)))).divide(g);
                    if(new_b.compareTo(best_ans) < 0)
                    {
                        best_ans = new_b;
                        m = (b.divide(BigInteger.valueOf(k).multiply(g))).multiply(BigInteger.valueOf(k).multiply(g));
                    }
                }
            }
            if(best_ans.compareTo(inf) == 0)
            {
                //System.out.println(b);
                return b.divide(g);
            }
            return best_ans.add(f(a, m));
        }
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a = in.nextLong(),
                b = in.nextLong();
        if(a == 1)
        {
            System.out.println(b);
            return;
        }
        BigInteger x = BigInteger.valueOf(a),
                y = BigInteger.valueOf(b);
        long new_a = a;
        for(long k = 2; k <= Math.sqrt(a); ++k)
        {
            if(new_a % k == 0)
            {
                arr[u++] = k;
                while(new_a % k == 0)
                {
                    new_a /= k;
                }
            }
        }
        if(new_a > 1)
        {
            arr[u++] = new_a;
        }
        System.out.println(f(x, y));
    }
    
}
