#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int N = 2000005;
bool isprime[N];
int f1[N], f2[N], p, q;
double dp[N];
void prime() {
  memset(isprime, true, sizeof(isprime));
  isprime[0] = isprime[1] = false;
  for (int i = 2; i < N; i++) {
    if (isprime[i]) {
      for (int j = i + i; j < N; j += i) {
        isprime[j] = false;
      }
    }
  }
}
bool chk(int x) {
  int a = 0, b = x;
  while (x) {
    a = a * 10 + x % 10;
    x /= 10;
  }
  return a == b;
}
void init() {
  prime();
  f1[0] = 0;
  for (int i = 1; i < N; ++i) {
    f1[i] = f1[i - 1];
    if (isprime[i]) f1[i]++;
  }
  f2[0] = 0;
  for (int i = 1; i < N; i++) {
    f2[i] = f2[i - 1] + (chk(i) ? 1 : 0);
  }
}
int main() {
  init();
  scanf("%d%d", &p, &q);
  double t = p * 1.0 / q;
  int ans = -1;
  for (int i = 1; i < N; ++i) {
    if (q * f1[i] <= p * f2[i]) ans = i;
  }
  if (ans == -1)
    puts("Palindromic tree is better than splay tree");
  else
    printf("%d\n", ans);
  return 0;
}
