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.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

/*
 public class _837E {

 }

 */

public class _837E
{
	class fac
	{
		long fact;
		long val;

		public fac(long fact, long val)
		{
			super();
			this.fact = fact;
			this.val = val;
		}

	}

	public void solve() throws FileNotFoundException
	{
		InputStream inputStream = System.in;

		InputHelper inputHelper = new InputHelper(inputStream);

		PrintStream out = System.out;

		// actual solution
		long x = inputHelper.readLong();
		long y = inputHelper.readLong();

		List<Long> xf = new ArrayList<Long>();

		for (long i = 1; i * i <= x; i++)
		{
			if (x % i == 0)
			{
				xf.add(i);
				if (i != x / i)
				{
					xf.add(x / i);
				}
			}
		}

		xf.sort((a, b) -> (int) Math.signum(a - b));

		Deque<fac> cp = new ArrayDeque<fac>();

		List<fac> facl = new ArrayList<_837E.fac>();

		for (int i = 0; i < xf.size(); i++)
		{
			long xfact = xf.get(i);

			long q = y / xfact;

			if (q == 0)
				continue;

			facl.add(new fac(xfact, q * xfact));
		}

		Collections.sort(facl, (f1, f2) ->
		{
			if (f1.val == f2.val)
				return (int) Math.signum(f2.fact - f1.fact);
			else
				return (int) Math.signum(f2.val - f1.val);
		});

		for (int i = 0; i < facl.size(); i++)
		{
			cp.addLast(facl.get(i));
		}

		fac ccp = cp.removeFirst();

		long ans = 0;

		while (true)
		{
			while (cp.size() > 0
					&& (ccp.val == cp.getFirst().val || (ccp.val - cp
							.getFirst().val) % ccp.fact != 0))
			{
				cp.removeFirst();
			}

			if (cp.size() > 0)
			{
				ans += (ccp.val - cp.getFirst().val) / ccp.fact;
				ccp = cp.removeFirst();
			}
			else
			{
				ans += (ccp.val) / ccp.fact;
				break;
			}
		}

		System.out.println(ans);
		// end here
	}

	public static void main(String[] args) throws FileNotFoundException
	{
		(new _837E()).solve();
	}

	class InputHelper
	{
		StringTokenizer tokenizer = null;
		private BufferedReader bufferedReader;

		public InputHelper(InputStream inputStream)
		{
			InputStreamReader inputStreamReader = new InputStreamReader(
					inputStream);
			bufferedReader = new BufferedReader(inputStreamReader, 16384);
		}

		public String read()
		{
			while (tokenizer == null || !tokenizer.hasMoreTokens())
			{
				try
				{
					String line = bufferedReader.readLine();
					if (line == null)
					{
						return null;
					}
					tokenizer = new StringTokenizer(line);
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}

			return tokenizer.nextToken();
		}

		public Integer readInteger()
		{
			return Integer.parseInt(read());
		}

		public Long readLong()
		{
			return Long.parseLong(read());
		}
	}
}