#include <bits/stdc++.h>
using namespace std;
const int M = 10000000;
int pi[M + 5];
int rub[M + 5];
int re[55];
bool isprime[M + 5];
int cal(int n) {
  int t = 0;
  while (n) {
    re[t++] = n % 10;
    n /= 10;
  }
  int ok = 1;
  for (int i = 0; i < t / 2; i++)
    if (re[i] != re[t - 1 - i]) ok = 0;
  return ok;
}
void FD() {
  isprime[1] = false;
  for (int i = 2; i <= M; i++) isprime[i] = true;
  for (int i = 2; i <= M; i++) {
    if (isprime[i]) {
      for (int j = i + i; j <= M; j += i) {
        isprime[j] = false;
      }
      pi[i] = pi[i - 1] + 1;
    } else
      pi[i] = pi[i - 1];
  }
}
int main() {
  int n;
  for (int i = 1; i <= M; i++) {
    rub[i] = rub[i - 1] + cal(i);
  }
  FD();
  int q, p;
  scanf("%d%d", &p, &q);
  for (int i = M; i >= 1; i--) {
    if (1ll * pi[i] * q <= 1ll * p * rub[i]) {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("Palindromic tree is better than splay tree\n");
  return 0;
}
