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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskE {
		List<Long> ps;

		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			long x = in.nextLong();
			long y = in.nextLong();
			calcPrimeDivisors(x);
			out.println(f(x, y));
		}

		private void calcPrimeDivisors(long x) {
			ps = new ArrayList<>();
			for (long p = 2; p * p <= x; p++) {
				if (x % p == 0) {
					ps.add(p);
					while (x % p == 0) {
						x /= p;
					}
				}
			}
			if (x > 1) {
				ps.add(x);
			}
		}

		private long f(long a, long b) {
			if (b == 0) {
				return 0;
			}
			long d = gcd(a, b);
			if (d != 1) {
				return f(a / d, b / d);
			}
			long bestB = 0;
			for (long p : ps) {
				long nb = (b - 1) / p * p;
				if (gcd(a, nb) != 1) {
					bestB = Math.max(bestB, nb);
				}
			}
			return b - bestB + f(a, bestB);
		}

		private long gcd(long a, long b) {
			return b == 0 ? a : gcd(b, a % b);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}

