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
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10;
const int MAXP = 1000000;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000000 + 7;
const double EPS = 1E-8;
typedef int ARRAY[MAXN];
typedef bool FLAG[MAXN];
long long mult_mod(long long a, long long b, long long m) {
  a %= m;
  b %= m;
  long long ret = 0, temp = a;
  while (b) {
    if (b & 1) {
      ret += temp;
      if (ret > m) ret -= m;
    }
    temp <<= 1;
    if (temp > m) temp -= m;
    b >>= 1;
  }
  return ret;
}
long long pow_mod(long long a, long long n, long long m) {
  long long ret = 1, temp = a % m;
  while (n) {
    if (n & 1) ret = mult_mod(ret, temp, m);
    temp = mult_mod(temp, temp, m);
    n >>= 1;
  }
  return ret;
}
bool check(long long a, long long n, long long x, long long t) {
  long long ret = pow_mod(a, x, n);
  long long last = ret;
  for (int i = 1; i <= t; ++i) {
    ret = mult_mod(ret, ret, n);
    if (ret == 1 && last != 1 && last != n - 1) return true;
    last = ret;
  }
  return (ret != 1);
}
bool Miller_Rabin(long long n) {
  if (n < 2) return false;
  if (n == 2) return true;
  if (!(n & 1)) return false;
  const static int S = 10;
  long long x = n - 1, t = 0;
  while (!(x & 1)) {
    x >>= 1;
    ++t;
  }
  for (int i = 0; i != S; ++i) {
    long long a = rand() % (n - 1) + 1;
    if (check(a, n, x, t)) return false;
  }
  return true;
}
long long gcd(long long a, long long b) {
  long long t;
  while (b) {
    t = a;
    a = b;
    b = t % b;
  }
  return a >= 0 ? a : -a;
}
long long pollard_rho(long long x, long long c) {
  long long i = 1, k = 2;
  long long x0 = rand() % (x - 1) + 1;
  long long y = x0;
  while (true) {
    ++i;
    x0 = (mult_mod(x0, x0, x) + c) % x;
    long long d = gcd(y - x0, x);
    if (d != 1 && d != x) return d;
    if (y == x0) return x;
    if (i == k) {
      y = x0;
      k += k;
    }
  }
}
const int MAX_FACTOR_NUM = 100;
long long factor[MAX_FACTOR_NUM];
int factor_num;
void findFactor(long long n) {
  if (n == 1) return;
  if (Miller_Rabin(n)) {
    factor[factor_num++] = n;
    return;
  }
  const static int C = 107;
  int c = C;
  long long p = n;
  while (p >= n) p = pollard_rho(p, c--);
  findFactor(p);
  findFactor(n / p);
}
void factorDecomposition(long long n) {
  factor_num = 0;
  findFactor(n);
}
long long f(long long x, long long y) {
  long long ret = 0;
  while (y) {
    long long g = gcd(x, y);
    x /= g;
    y /= g;
    factorDecomposition(x);
    long long m = y;
    for (int i = 0; i < factor_num; ++i)
      m = min(m, y - (y / factor[i] * factor[i]));
    y -= m;
    ret += m;
  }
  return ret;
}
int main() {
  long long x, y;
  scanf(
      "%lld"
      "%lld",
      &x, &y);
  printf("%lld", f(x, y));
  return 0;
}
