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 long long Inf = 1000000000000000000ll;
const int inf = 1000000000;
vector<long long> pri, fac;
long long m, x, ans;
void getpri(long long t, vector<long long>& v) {
  v.clear();
  for (long long i = 2; i * i <= t; ++i) {
    if (t % i) continue;
    v.push_back(i);
    while (t % i == 0) t /= i;
  }
  if (t != 1) v.push_back(t);
  sort(v.begin(), v.end());
}
long long Euler(long long t) {
  long long res = t;
  for (int i = 0; i < pri.size(); ++i)
    if (t % pri[i] == 0) res = res / pri[i] * (pri[i] - 1);
  return res;
}
long long mul(long long x, long long y, long long mod) {
  long long res = 0;
  while (y) {
    if (y & 1) (res += x) >= mod && (res -= mod);
    (x <<= 1) >= mod && (x -= mod);
    y >>= 1ll;
  }
  return res;
}
long long qpow(long long b, long long p, long long mod) {
  long long res = 1ll;
  b %= mod;
  while (p) {
    if (p & 1ll) res = mul(b, res, mod);
    b = mul(b, b, mod);
    p >>= 1ll;
  }
  return res;
}
void work(long long md) {
  long long f_d = Euler(md);
  long long l_d = f_d;
  if (l_d > 1) {
    for (int j = 0; j < fac.size(); ++j)
      while (l_d % fac[j] == 0 && qpow(x, l_d / fac[j], md) == 1) l_d /= fac[j];
  }
  ans += f_d / l_d;
}
int main() {
  scanf("%lld%lld", &m, &x);
  getpri(m, pri);
  long long eul = Euler(m);
  if (eul > 1)
    getpri(eul, fac);
  else
    fac.push_back(1);
  for (long long i = 1; i * i <= m; ++i) {
    if (m % i) continue;
    work(i);
    if (i * i != m) work(m / i);
  }
  printf("%lld\n", ans);
  return 0;
}