Problem: The campus has m rooms numbered from 0 to m - 1. Also the x-mouse lives in the campus. The x-mouse is not just a mouse: each second x-mouse moves from room i to the room i ⋅ x mod{m} (in fact, it teleports from one room to another since it doesn't visit any intermediate room). Starting position of the x-mouse is unknown.

You are responsible to catch the x-mouse in the campus, so you are guessing about minimum possible number of traps (one trap in one room) you need to place. You are sure that if the x-mouse enters a trapped room, it immediately gets caught.

And the only observation you made is GCD (x, m) = 1.

Input

The only line contains two integers m and x (2 ≤ m ≤ 10^{14}, 1 ≤ x < m, GCD (x, m) = 1) — the number of rooms and the parameter of x-mouse. 

Output

Print the only integer — minimum number of traps you need to install to catch the x-mouse.

Examples

Input

4 3


Output

3


Input

5 2


Output

2

Note

In the first example you can, for example, put traps in rooms 0, 2, 3. If the x-mouse starts in one of this rooms it will be caught immediately. If x-mouse starts in the 1-st rooms then it will move to the room 3, where it will be caught.

In the second example you can put one trap in room 0 and one trap in any other room since x-mouse will visit all rooms 1..m-1 if it will start in any of these rooms.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#pragma GCC optimize("O5")
using namespace std;
const long long maxn = 2e7 + 1000;
long long m, x;
long long pr[maxn], spr;
bool mark[maxn];
const long long lg = 12, base = (1 << lg) - 1;
inline long long mul(long long a, long long b, long long m) {
  if (b == 0) return 0;
  long long ans = ((b & base) * a) % m;
  ans = (ans + mul((a << lg) % m, b >> lg, m)) % m;
  return ans;
}
long long power(long long b, long long m) {
  long long a = x % m, ans = 1;
  while (b > 0ll) {
    if (b & 1ll) {
      ans = mul(ans, a, m);
    }
    a = mul(a, a, m);
    b >>= 1ll;
  }
  return ans;
}
void sieve() {
  for (long long i = 2; i < maxn; i++) {
    if (mark[i]) continue;
    pr[spr++] = i;
    for (long long j = i; j < maxn; j += i) {
      mark[j] = 1;
    }
  }
}
long long ans = 0;
void solve(long long m) {
  long long phi = m, s = m;
  for (long long i = 0; 1ll * pr[i] * pr[i] <= s; i++) {
    if (s % pr[i] == 0) {
      while (s % pr[i] == 0) {
        s /= pr[i];
      }
      phi -= phi / pr[i];
    }
  }
  if (s > 1) {
    phi -= phi / s;
  }
  long long d = phi, o = phi;
  for (long long i = 0; 1ll * pr[i] * pr[i] <= d; i++) {
    if (d % pr[i] == 0) {
      while (d % pr[i] == 0 && power(d / pr[i], m) == 1) {
        d /= pr[i];
      }
      while (o % pr[i] == 0) {
        o /= pr[i];
      }
    }
  }
  if (o > 1 && power(d / o, m) == 1) {
    d /= o;
  }
  ans += phi / d;
}
int32_t main() {
  sieve();
  scanf("%lld%lld", &m, &x);
  for (long long i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      solve(m / i);
      if (i != m / i) {
        solve(i);
      }
    }
  }
  printf("%lld\n", ans);
}