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;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 5;
long long read() {
  long long s = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    s = s * 10 + c - '0';
    c = getchar();
  }
  return s * f;
}
long long n, X, tot, cnt1, cnt2, num[N], p1[N], p2[N];
long long Multi(long long x, long long y, long long mod) {
  return ((unsigned long long)x * y -
          (unsigned long long)((long double)x / mod * y) * mod + mod) %
         mod;
}
long long Pow(long long x, long long y, long long mod) {
  long long ans = 1;
  x %= mod;
  while (y) {
    if (y & 1) ans = Multi(ans, x, mod);
    x = Multi(x, x, mod);
    y >>= 1;
  }
  return ans;
}
void Divide(long long n) {
  for (long long i = 1; i * i <= n; i++)
    if (n % i == 0) {
      num[++tot] = i;
      if (i * i != n) num[++tot] = n / i;
    };
  sort(num + 1, num + tot + 1);
}
void GetPrime(long long n, long long p[], long long &tot) {
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) {
      p[++tot] = i;
      while (n % i == 0) n /= i;
    }
  if (n != 1) p[++tot] = n;
}
long long Phi(long long n) {
  long long phi = n;
  for (int i = 1; i <= cnt1; i++)
    if (n % p1[i] == 0) phi = phi / p1[i] * (p1[i] - 1);
  return phi;
}
long long Solve(long long n) {
  long long phi = Phi(n), ans = 0;
  if (phi != 1) GetPrime(phi, p2, cnt2);
  for (int i = 1; i <= tot; i++) {
    long long F = Phi(num[i]), L = F;
    for (int j = 1; j <= cnt2; j++) {
      while (L % p2[j] == 0 && Pow(X, L / p2[j], num[i]) == 1) L /= p2[j];
    }
    ans += F / L;
  }
  return ans;
}
int main() {
  n = read();
  X = read();
  Divide(n);
  GetPrime(n, p1, cnt1);
  printf("%lld", Solve(n));
  return 0;
}