#include <bits/stdc++.h>
using namespace std;
const int maxn = 1200000;
bool vis[maxn];
int prim[maxn];
int huwen[maxn];
bool judge_huiwen(int n) {
  int sign = 0;
  int a[15];
  while (n) {
    a[sign] = n % 10;
    n = n / 10;
    sign++;
  }
  for (int i = 0, j = sign - 1; i < j; i++, j--) {
    if (a[i] != a[j]) return false;
  }
  return true;
}
void prim_init() {
  memset(vis, false, sizeof(vis));
  vis[0] = vis[1] = true;
  int cou = 0;
  for (int i = 2; i < maxn; i++) {
    if (!vis[i]) {
      cou++;
      for (int j = i + i; j < maxn; j = j + i) vis[j] = true;
    }
    prim[i] = cou;
  }
}
int main() {
  int p, q;
  scanf("%d%d", &p, &q);
  prim_init();
  int couh = 0;
  for (int i = 1; i < maxn; i++) {
    if (judge_huiwen(i)) {
      couh++;
    }
    huwen[i] = couh;
  }
  int ans = -1;
  for (int i = maxn - 1; i > 0; i--) {
    if (q * prim[i] <= p * huwen[i]) {
      ans = i;
      break;
    }
  }
  if (ans == -1)
    printf("Palindromic tree is better than splay tree\n");
  else
    printf("%d\n", ans);
  return 0;
}
