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 hackerrank;

import java.util.ArrayList;
import java.util.Scanner;

public class Code {
	
	public static ArrayList<Long> divisors(long n) {
		ArrayList<Long> ar = new ArrayList<>();
		long tempN = n; // dont want to modify the var n
		for(long i = 2; i< Math.ceil(Math.sqrt(n)) + 1; i++) { // focus on loop condition, tempN not n
			while(tempN % i == 0) {
				ar.add(i);
				tempN /= i;
			}
		}
		if(tempN > 1) ar.add(tempN);
		return ar;
	}
	public static long f(long a, long b, ArrayList<Long> divisorsOfA) {
		if(b <= 1) return b;
		
		ArrayList<Long> commonDivisorsOfAB = new ArrayList<>();
		long gcd = 1;
		long lastB = b;
		for(Long divisor: divisorsOfA) {
			if(b % divisor == 0) {
				gcd *= divisor;
				
				// reduce b in case gcd(a,b) == 1
				b /= divisor;
				commonDivisorsOfAB.add(divisor);
			}
		}
		
		if(!commonDivisorsOfAB.isEmpty()) { // Case gcd(a,b) != 1
			for(Long divisor: commonDivisorsOfAB) 
				divisorsOfA.remove(divisor);
			return 1 + f(a/gcd, lastB/gcd - 1, divisorsOfA);
		}
		
		// Case gcd(a,b) = 1
		// example (10001,60) 10001 = 7*11*13
		/*
		 * Truong hop nay b no se giam 1 giam 1
		 * Den luc nao do no se chia het cho 1 trong cac divisor cua a.
		 * Divisor dau tien ma no chia het trong (7,11,13) chinh la so 7.
		 * Vi sao, do 60 % 7 < 60 % 11 < 60 % 13 (cai hay cua solution o day !!)
		 */
		long minRemainder = Long.MAX_VALUE;
		for(Long divisor: divisorsOfA) {
			long remainder = b % divisor;
			minRemainder = Math.min(minRemainder, remainder);
		}
		return minRemainder + f(a, b - minRemainder, divisorsOfA);
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		long x = in.nextLong();
		long y = in.nextLong();
		
		ArrayList<Long> divisorsOfX = divisors(x);
		System.out.println(f(x, y, divisorsOfX));
		in.close();
	}

}
