#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, tmp_b, ans;
  ans = 0;
  int flag = 0;
  long long tmp;
  cin >> a >> b;
  int tmp_1;
  if (a != 1 && b != 1) {
    tmp_1 = sqrt(b);
    int prime[tmp_1];
    for (long long i = 2; i < tmp_1 + 1; i++) {
      tmp_b = b;
      if (tmp_b % i == 0) {
        prime[i] = 0;
        while (tmp_b % i == 0) {
          tmp_b = tmp_b / i;
          prime[i] += 1;
        }
      } else {
        prime[i] = -1;
      }
    }
    for (int i = 0; i < tmp_1 + 1; i++) {
      if (prime[i] % a == 0 && prime[i] != -1) {
        ans = i;
      }
    }
    cout << ans << endl;
  } else if (b == 1) {
    cout << b << endl;
  } else {
    cout << b << endl;
  }
}
