#include <bits/stdc++.h>
using namespace std;
bool isPrime[1200000];
int Prisum[1200000], Palsum[1200000];
vector<int> prime, pal;
void PrimeInit() {
  memset(isPrime, true, sizeof isPrime);
  isPrime[0] = isPrime[1] = false;
  Prisum[0] = Prisum[1] = 0;
  prime.clear();
  for (int i = 2; i < 1200000; i++) {
    if (isPrime[i] == false) {
      Prisum[i] = Prisum[i - 1];
      continue;
    }
    Prisum[i] = Prisum[i - 1] + 1;
    prime.push_back(i);
    for (int k = i + i; k <= 1200000; k += i) isPrime[k] = false;
  }
}
bool ok(int x) {
  int a[30], cnt = 0;
  while (x) {
    a[cnt++] = x % 10;
    x /= 10;
  }
  for (int i = 0; i < cnt / 2; i++) {
    if (a[i] != a[cnt - 1 - i]) return false;
  }
  return true;
}
void PalInit() {
  int ans = 0;
  Palsum[0] = 0;
  for (int i = 1; i < 1200000; i++) {
    if (ok(i)) {
      Palsum[i] = Palsum[i - 1] + 1;
    } else
      Palsum[i] = Palsum[i - 1];
  }
}
int main() {
  PrimeInit();
  PalInit();
  int p, q;
  while (scanf("%d %d", &p, &q) != EOF) {
    int tag = -1;
    for (int i = 1200000 - 1; i >= 0; i--) {
      if (Prisum[i] * q <= Palsum[i] * p) {
        tag = i;
        break;
      }
    }
    if (tag != -1)
      printf("%d\n", tag);
    else
      printf("Palindromic tree is better than splay tree");
  }
  return 0;
}
