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 LLmul(long long a, long long b, long long mod) {
  return (a * b - (long long)((long double)a * b / mod) * mod) % mod;
}
long long powmod(long long x, long long p, long long mod) {
  long long s = 1, m = x % mod;
  for (; p; m = LLmul(m, m, mod), p >>= 1)
    if (p & 1) s = LLmul(s, m, mod);
  return s;
}
vector<pair<long long, int>> factor(long long N) {
  vector<pair<long long, int>> ans;
  for (long long p = 2; p * p <= N; ++p)
    if (N % p == 0) {
      ans.emplace_back(p, 0);
      while (N % p == 0) N /= p, ++ans.back().second;
    }
  if (N != 1) ans.emplace_back(N, 1);
  return ans;
}
long long phi(long long m) {
  auto fac = factor(m);
  auto LL_pow = [](long long p, int t) {
    long long ans = 1;
    for (long long cur = p; t; t >>= 1, cur *= cur)
      if (t & 1) ans *= cur;
    return ans;
  };
  return accumulate(fac.begin(), fac.end(), 1ll,
                    [=](long long a, pair<long long, int> p_r) {
                      return a * (LL_pow(p_r.first, p_r.second) -
                                  LL_pow(p_r.first, p_r.second - 1));
                    });
}
long long order(long long x, long long m) {
  long long ans = phi(m);
  auto phi_fac = factor(ans);
  for (auto P : phi_fac) {
    long long p = P.first, t = P.second;
    for (int i = 0; i < t; ++i) {
      if (powmod(x, ans / p, m) == 1)
        ans /= p;
      else
        break;
    }
  }
  return ans;
}
long long cycles(long long a, long long m) {
  if (m == 1) return 1;
  return phi(m) / order(a, m);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long m, x;
  cin >> m >> x;
  long long ans = 0;
  for (long long g = 1; g * g <= m; ++g) {
    if (m % g == 0) {
      ans += cycles(x % (m / g), m / g);
      if (g * g != m) ans += cycles(x % g, g);
    }
  }
  cout << ans << '\n';
}