#include <bits/stdc++.h>
using namespace std;
const double PI = 2.0 * acos(0.0);
const double EPS = 1e-9;
int cases = 1;
double getdist(pair<int, int> a, pair<int, int> b) {
  return sqrt(pow((double)a.first - b.first, 2) +
              pow((double)a.second - b.second, 2));
}
const int MAX = 1200000 + 5;
int N, csum[MAX], c, palinSum[MAX];
bool flag[MAX], primes[MAX + 5];
char str[15];
void read() {
  primes[2] = true;
  for (int i = 3; i < MAX; i += 2) {
    if (flag[i] == 0) {
      primes[i] = true;
      if (i >= MAX / i) continue;
      for (int j = i * i; j <= MAX; j += i) {
        flag[j] = 1;
      }
    }
  }
  return;
}
bool isPalin(int n) {
  sprintf(str, "%d", n);
  for (int i = 0, j = strlen(str) - 1; i < j; i++, j--) {
    if (str[i] != str[j]) return 0;
  }
  return true;
}
int main() {
  int test;
  read();
  csum[2] = 1;
  palinSum[1] = 1;
  for (int i = 2; i < MAX; i++) {
    csum[i] = csum[i - 1] + primes[i];
    palinSum[i] = palinSum[i - 1] + isPalin(i);
  }
  long long p, q, save = -1;
  while (cin >> p >> q) {
    for (int i = 1; i < MAX; i++) {
      if (p * palinSum[i] >= q * csum[i]) {
        save = i;
      }
    }
    if (save == -1)
      puts("Palindromic tree is better than splay tree");
    else
      cout << save << endl;
  }
  return 0;
}
