#include <bits/stdc++.h>
using namespace std;
const int inft = 1000000009;
const int MAXN = 2000006;
bool P[MAXN];
int SP[MAXN];
int PAL[MAXN];
char S[123];
bool pal(int a) {
  sprintf(S, "%d", a);
  reverse(S, S + strlen(S));
  int q;
  sscanf(S, "%d", &q);
  return a == q;
}
int main() {
  for (int i = 0; i < (MAXN); ++i) P[i] = 1;
  for (int i = 2; i < MAXN; ++i)
    if (P[i])
      for (int j = 2 * i; j < MAXN; j += i) P[j] = 0;
  P[0] = P[1] = 0;
  for (int i = 0; i < (MAXN); ++i)
    if (i) SP[i] = SP[i - 1] + P[i];
  for (int i = 1; i < MAXN; ++i) PAL[i] = PAL[i - 1] + pal(i);
  int ret = 0;
  int p, q;
  scanf("%d%d", &p, &q);
  for (int i = 0; i < (MAXN); ++i)
    if (i && q * SP[i] <= p * PAL[i]) ret = i;
  if (ret)
    printf("%d\n", ret);
  else
    printf("Palindromic tree is better than splay tree\n");
  return 0;
}
