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>
using namespace std;
inline long long read() {
  long long neg = 1, num = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') neg = -1;
  for (; isdigit(c); c = getchar()) num = (num << 1) + (num << 3) + c - '0';
  return neg * num;
}
struct prime {
  long long tot, pri[100], cnt[100];
} M, A[100];
long long m, x, ans, p[1010], a[1010];
inline long long Mul(long long x, long long y, long long d) {
  long long sum = x * y - (long long)((long double)x * y / d + 0.5) * d;
  return sum < 0 ? sum + d : sum;
}
inline long long Pow(long long x, long long y, long long d) {
  long long sum = 1;
  for (; y; y >>= 1, x = Mul(x, x, d))
    if (y & 1) sum = Mul(sum, x, d);
  return sum;
}
inline void Init(prime &x, long long tmp, long long opt) {
  for (long long i = 2; i * i <= tmp; i++)
    if (tmp % i == 0) {
      x.pri[++x.tot] = i;
      while (tmp % i == 0) x.cnt[x.tot]++, tmp /= i;
      if (opt) Init(A[x.tot], i - 1, 0ll);
    }
  if (tmp != 1) {
    x.pri[++x.tot] = tmp;
    x.cnt[x.tot] = 1;
    if (opt) Init(A[x.tot], tmp - 1, 0ll);
  }
}
inline void Solve(long long d) {
  long long phi = 1, sum = 0, cnt = 0;
  for (long long i = 1; i <= M.tot; i++)
    if (d % M.pri[i] == 0) {
      long long tmp = d / M.pri[i];
      while (tmp % M.pri[i] == 0) p[++cnt] = M.pri[i], tmp /= M.pri[i];
      for (long long j = 1; j <= A[i].tot; j++)
        for (long long k = 1; k <= A[i].cnt[j]; k++) p[++cnt] = A[i].pri[j];
    }
  sort(p + 1, p + cnt + 1);
  sum = 0;
  for (long long i = 1; i <= cnt; i++) phi *= p[i], a[i] = 0;
  for (long long i = 1; i <= cnt; i++) {
    long long j = i;
    while (p[j + 1] == p[i] && j < cnt) j++;
    a[++sum] = j - i + 1;
    p[sum] = p[i];
    i = j;
  }
  cnt = sum;
  sum = 1;
  for (long long i = 1; i <= cnt; i++) {
    long long tmp = phi;
    for (long long j = 1; j <= a[i]; j++) {
      tmp /= p[i];
      if (Pow(x % d, tmp, d) != 1) break;
      sum = sum * p[i];
    }
  }
  ans += sum;
}
signed main() {
  m = read();
  x = read();
  Init(M, m, 1ll);
  for (long long i = 1; i * i <= m; i++)
    if (m % i == 0) {
      Solve(i);
      if (i * i != m) Solve(m / i);
    }
  printf("%lld", ans);
  return 0;
}