#include <bits/stdc++.h>
const int maxn = 1500000 + 10;
bool is_prime[maxn];
int primeindex[maxn] = {0};
int huiwen[maxn] = {0};
void prime_table() {
  memset(is_prime, 0, sizeof(is_prime));
  is_prime[0] = is_prime[1] = 1;
  for (int i = 2; i < maxn; i++) {
    if (is_prime[i]) {
      primeindex[i] = primeindex[i - 1];
      continue;
    } else
      primeindex[i] = primeindex[i - 1] + 1;
    for (int j = 2 * i; j < maxn; j += i) is_prime[j] = 1;
  }
}
int is_huiwenshu(int m) {
  int n = m;
  int i = 0, j = 0;
  while (n != 0) {
    i = n % 10;
    j = j * 10 + i;
    n /= 10;
  }
  if (j == m)
    return 1;
  else
    return 0;
}
void huiwenshu() {
  for (int i = 1; i < maxn; i++) {
    if (is_huiwenshu(i))
      huiwen[i] = huiwen[i - 1] + 1;
    else
      huiwen[i] = huiwen[i - 1];
  }
}
int main() {
  int p, q, i = maxn;
  int n = 0;
  prime_table();
  huiwenshu();
  scanf("%d%d", &p, &q);
  for (i = maxn - 1; i >= 1; i--) {
    if (q * primeindex[i] <= p * huiwen[i]) {
      n = i;
      break;
    }
  }
  if (i == 0)
    printf("Palindromic tree is better than splay tree");
  else
    printf("%d", n);
  return 0;
}
