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;
template <class T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <typename Args>
void kill(Args args) {
  cout << args << "\n";
  exit(0);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
set<long long> st;
long long curg = 1;
int n;
long long f[102], fr[102], curtally[102], c;
long long ans = 0;
void go(long long b) {
  if (b == 0) {
    cout << ans << "\n";
    return;
  }
  for (int i = 1; i <= c; i++) {
    while (curtally[i] < fr[i] && b % (curg * f[i]) == 0) {
      curg *= f[i];
      curtally[i]++;
    }
  }
  long long maxx = 0;
  long long tempg = curg;
  int idx = 0;
  for (int i = 1; i <= c; i++) {
    if (curtally[i] < fr[i]) {
      long long temp = curg * f[i];
      long long temp1 = b / temp;
      if (maxx < temp1 * temp) {
        idx = i;
        tempg = temp;
        maxx = temp1 * temp;
      }
    }
  }
  curtally[idx]++;
  ans += (b - maxx) / curg;
  curg = tempg;
  go(maxx);
}
void solve(int testnum) {
  long long a, b;
  cin >> a >> b;
  if (a == 1) {
    kill(b);
  }
  long long k = a;
  for (long long i = 2; i * i <= k; i++) {
    if (k % i == 0) {
      f[++c] = i;
      while (k % i == 0) {
        fr[c]++;
        k /= i;
      }
    }
  }
  if (k > 1) {
    f[++c] = k;
    fr[c] = 1;
  }
  go(b);
}
void precompute() {}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  int testcase = 1;
  clock_t zzzx = clock();
  precompute();
  for (int i = 1; i <= testcase; i++) {
    solve(i);
  }
  double elapsed_time = (double)(clock() - zzzx) / CLOCKS_PER_SEC;
  cerr << "elapsed_time"
       << " = " << (elapsed_time) << "\n";
  return 0;
}
