#include <bits/stdc++.h>
using namespace std;
vector<long int> primes;
vector<long int> palin;
bool B[1300001];
int palintest(long int u) {
  vector<int> digits;
  long int i = 1;
  while (u / i != 0) i *= 10;
  i = i / 10;
  for (long int j = i; j > 0; j /= 10) {
    digits.push_back(u / j);
    u = u % j;
  }
  int k = 1;
  for (long int j = 0; j < digits.size(); j++) {
    if (digits[j] != digits[digits.size() - 1 - j]) k = 0;
  }
  return k;
}
void sieve() {
  B[0] = true;
  B[1] = true;
  for (long int i = 2; i < 1300000; i++) {
    if (!B[i]) {
      primes.push_back(i);
      for (long int j = 1; j * i < 1300000; j++) B[j * i] = true;
    }
    if (palintest(i)) palin.push_back(i);
  }
}
int main() {
  long int p, q;
  cin >> p >> q;
  memset(B, false, sizeof B);
  palin.push_back(1);
  sieve();
  float c, d;
  c = (float)p / q;
  long int l = 0, r = 1300000, m, a, b;
  while (l < r) {
    m = (l + r) / 2;
    a = upper_bound(palin.begin(), palin.end(), m) - palin.begin();
    b = upper_bound(primes.begin(), primes.end(), m) - primes.begin();
    d = (float)b / a;
    if (d < c)
      l = m + 1;
    else
      r = m - 1;
  }
  int maxx;
  for (long int i = max(l - 100000, (long int)0);
       i < min((long int)1300000, l + 100000); i++) {
    a = upper_bound(palin.begin(), palin.end(), i) - palin.begin();
    b = upper_bound(primes.begin(), primes.end(), i) - primes.begin();
    d = (float)b / a;
    if (d <= c) maxx = i;
  }
  cout << maxx;
  return 0;
}
