#include <bits/stdc++.h>
using namespace std;
const int n = 5000000;
int tot, pri[n], p, q, tp[n + 10], a[10];
bool nop[n + 10];
void pre() {
  long long num;
  for (int i = 2; i <= n; i++) {
    if (!nop[i]) pri[++tot] = i;
    for (int j = 1; (num = (long long)pri[j] * i) <= n && j <= tot; j++) {
      nop[num] = 1;
      if (i % pri[j] == 0) break;
    }
    tp[i] = tp[i - 1] + (!nop[i]);
  }
}
bool hui(int x) {
  int tt = 0;
  while (x) a[++tt] = x % 10, x /= 10;
  for (int i = 1; i <= tt / 2; i++)
    if (a[i] != a[tt - i + 1]) return 0;
  return 1;
}
int main() {
  scanf("%d%d", &p, &q);
  pre();
  tot = 0;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (hui(i)) tot++;
    if ((long long)q * tp[i] <= (long long)p * tot) ans = i;
  }
  if (ans)
    printf("%d\n", ans);
  else
    printf("Palindromic tree is better than splay tree\n");
  return 0;
}
