#include <bits/stdc++.h>
using namespace std;
int pri[2000001];
int nb[2000001];
bool ispal(long long q) {
  vector<int> nu;
  while (q) {
    nu.push_back(q % 10);
    q /= 10;
  }
  for (int i = 0; i < nu.size() / 2; i++) {
    if (nu[i] != nu[nu.size() - 1 - i]) return 0;
  }
  return 1;
}
void sive() {
  nb[1] = 1;
  int np = 0;
  int nb1 = 1;
  for (long long y = 2; y <= 2000000; y++) {
    if (ispal(y)) {
      nb1++;
      nb[y] = nb1;
    } else {
      nb[y] = nb1;
    }
    if (!pri[y]) {
      np++;
      pri[y] = np;
      long long z = y * y;
      while (z <= 2000000) {
        pri[z] = 1;
        z += y;
      }
    } else {
      pri[y] = np;
    }
  }
}
int main() {
  sive();
  int p, q;
  cin >> p >> q;
  int re = -1;
  for (int y = 2000000; y >= 1; y--) {
    long long qq = q * pri[y];
    long long qq1 = p * nb[y];
    if (qq <= qq1) {
      cout << y << "\n";
      return 0;
    }
  }
  if (re == -1) {
    cout << "Palindromic tree is better than splay tree\n";
  }
}
