#include <bits/stdc++.h>
using namespace std;
int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
bool prime[10001000], pdrome[10001000] = {0};
int prefixprime[10001000] = {0}, prefixdrome[10001000] = {0};
int main() {
  memset(prime, 1, sizeof(prime));
  prime[0] = prime[1] = 0;
  prime[2] = 1;
  for (int i = 2; i <= (int)sqrt(10000000); i++) {
    if (!prime[i]) continue;
    for (int j = i * i; j <= 10000000; j += i) prime[j] = 0;
  }
  for (int i = 2; i <= 10000000; i++) {
    if (prime[i])
      prefixprime[i] = prefixprime[i - 1] + 1;
    else
      prefixprime[i] = prefixprime[i - 1];
  }
  for (int i = 1; i <= 10000000; i++) {
    bool yes = 1;
    int idx = 0, helper = i;
    char S[10];
    while (helper > 0) {
      S[idx++] = helper % 10 + '0';
      helper /= 10;
    }
    for (int j = 0, k = idx - 1; j < k; j++, k--) {
      if (S[j] != S[k]) {
        yes = 0;
        break;
      }
    }
    if (yes) pdrome[i] = 1;
  }
  for (int i = 1; i <= 10000000; i++) {
    if (pdrome[i])
      prefixdrome[i] = prefixdrome[i - 1] + 1;
    else
      prefixdrome[i] = prefixdrome[i - 1];
  }
  int P, Q, ans = -1;
  scanf("%d%d", &P, &Q);
  for (int i = 0; i < 10000000; i++) {
    if ((double)prefixprime[i] <= ((double)P * prefixdrome[i]) / (double)Q) {
      ans = i;
    }
  }
  if (ans == -1)
    puts("Palindromic tree is better than splay tree");
  else
    printf("%d\n", ans);
  return 0;
}
