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;
static inline void canhazfast() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
  T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
  while (b) {
    T q = a / b;
    a %= b;
    swap(a, b);
    x0 -= q * x1;
    swap(x0, x1);
    y0 -= q * y1;
    swap(y0, y1);
  }
  x = x0;
  y = y0;
  return a;
}
static inline int ctz(unsigned x) { return __builtin_ctz(x); }
static inline int ctzll(unsigned long long x) { return __builtin_ctzll(x); }
static inline int clz(unsigned x) { return __builtin_clz(x); }
static inline int clzll(unsigned long long x) { return __builtin_clzll(x); }
static inline int popcnt(unsigned x) { return __builtin_popcount(x); }
static inline int popcntll(unsigned long long x) {
  return __builtin_popcountll(x);
}
static inline int bsr(unsigned x) { return 31 ^ clz(x); }
static inline int bsrll(unsigned long long x) { return 63 ^ clzll(x); }
void get(unsigned long long n, vector<unsigned long long> &pfs) {
  int e2 = ctzll(n);
  n >>= e2;
  if (e2) pfs.push_back(2);
  for (unsigned long long p = 3;; p += 2) {
    unsigned long long q = n / p, r = n % p;
    if (q < p) break;
    if (r) continue;
    pfs.push_back(p);
    do {
      n = q;
      q = n / p;
      r = n % p;
    } while (!r);
  }
  if (n > 1) pfs.push_back(n);
}
int main() {
  canhazfast();
  unsigned long long x, y, ans = 0;
  vector<unsigned long long> pfs;
  cin >> x >> y;
  get(x, pfs);
  while (y) {
    unsigned long long d = gcd(x, y);
    unsigned long long t = y / d, cnt = t;
    for (unsigned long long p : pfs) {
      unsigned long long r = t % p;
      if (r) cnt = min(cnt, r);
    }
    ans += cnt;
    y -= cnt * d;
  }
  cout << ans;
  return 0;
}
