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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;


public class ED26E
{
	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long y = sc.nextLong();
		ArrayList<Long> div = new ArrayList<Long>();
		for (int i = 1; 1l*i*i <= x; i++)
		{
			if(x%i == 0)
			{
				div.add(1l*i);
				if(x/i != i)
					div.add(x/i);
			}
		}
		long ans = 0;
		while(y != 0)
		{
			if(y%x == 0)
			{
				ans += y/x;
				break;
			}
			long g = gcd(x, y);
			long k = Long.MAX_VALUE;
			for (long d : div)
			{
				long kg = d*g;
				long diff = y % kg;
				if(diff == 0 || diff % g != 0)
					continue;
				k = Math.min(k, diff/g);
			}
			ans += k;
			y -= (g*k);
		}
		
		System.out.println(ans);
	}
	
	static long gcd(long x, long y)
	{
		if(y == 0)
			return x;
		return gcd(y, x%y);
	}
	
		static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException {return Integer.parseInt(next());}
		public long nextLong() throws IOException {return Long.parseLong(next());}
		public String nextLine() throws IOException {return br.readLine();}
		public double nextDouble() throws IOException{return Double.parseDouble(next());}
		public boolean ready() throws IOException {return br.ready();}
	}
}
