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;
long long n, x, m, ans;
long long p[100], q[1010];
int c1, c2;
void d(long long a) {
  for (int i = 2; (long long)i * i <= a; i++)
    if (a % i == 0) {
      q[++c2] = i;
      while (a % i == 0) a /= i;
    }
  if (a > 1) q[++c2] = a;
}
inline long long cheng(long long x, long long y, long long mod) {
  return ((x * y - (long long)(((long double)x * y + 0.5) / mod) * mod) % mod +
          mod) %
         mod;
}
inline long long phi(long long a) {
  long long res = a;
  for (int i = 1; i <= c1; i++)
    if (a % p[i] == 0) res = res / p[i] * (p[i] - 1);
  return res;
}
long long ksm(long long a, long long b, long long mod) {
  long long res = 1;
  for (a %= mod; b; b >>= 1, a = cheng(a, a, mod))
    if (b & 1) res = cheng(res, a, mod);
  return res;
}
long long solve(long long a) {
  long long mod = n / a, t = phi(mod), tmp = t, xd = x % mod;
  for (int i = 1; i <= c2; i++) {
    while (tmp % q[i] == 0 && ksm(xd, tmp / q[i], mod) == 1) tmp /= q[i];
  }
  return t / tmp;
}
int main() {
  scanf("%lld %lld", &n, &x);
  m = n;
  for (int i = 2; (long long)i * i <= m; i++)
    if (m % i == 0) {
      p[++c1] = i;
      while (m % i == 0) m /= i;
    }
  if (m > 1) p[++c1] = m;
  for (int i = 1; i <= c1; i++) {
    q[++c2] = p[i];
    d(p[i] - 1);
  }
  sort(q + 1, q + (c2 + 1));
  c2 = unique(q + 1, q + (c2 + 1)) - q - 1;
  for (register int i = 1; (long long)i * i <= n; ++i)
    if (n % i == 0) {
      ans += solve(i);
      if (n / i != i) ans += solve(n / i);
    }
  printf("%lld\n", ans);
  return 0;
}