#include <bits/stdc++.h>
using namespace std;
bool sieve[10000007];
bool pal[10000007];
int ispal(int x) {
  if (!x) return 0;
  char str[10];
  int i, c = 0;
  while (x) {
    str[c] = (x % 10);
    c++;
    x /= 10;
  }
  for (i = 0; i < c; i++)
    if (str[i] != str[c - i - 1]) return 0;
  return 1;
}
int pi[10000000];
int rub[10000000];
int main() {
  int i, j;
  for (i = 2; i <= 2000000; i++) sieve[i] = 1;
  for (i = 2; i <= 1415; i++) {
    if (sieve[i]) {
      for (j = i * i; j <= 2000000; j += i) sieve[j] = 0;
    }
  }
  pi[0] = 0;
  for (i = 1; i <= 2000000; i++) {
    pi[i] = pi[i - 1] + sieve[i];
  }
  rub[0] = 0;
  for (i = 1; i <= 2000000; i++) {
    rub[i] = rub[i - 1] + ispal(i);
  }
  int p, q, ans = -1;
  scanf("%d%d", &p, &q);
  for (i = 1; i <= 2000000; i++) {
    long long v1, v2;
    v1 = (long long)q * pi[i];
    v2 = (long long)p * rub[i];
    if (v1 <= v2) ans = i;
  }
  if (ans != -1)
    printf("%d\n", ans);
  else
    puts("Palindromic tree is better than splay tree");
  return 0;
}
