#include <bits/stdc++.h>
using namespace std;
const int M = 1179858 + 3;
double p, q;
bool prime[M];
int ans, pri, pal;
void getprime() {
  prime[1] = false;
  for (int i = 2; i < M; i++) {
    if (!prime[i]) continue;
    prime[i] = true;
    for (int j = 2; j * i < M; j++) prime[i * j] = false;
  }
}
bool palindromic(int n) {
  int fn = 0;
  int aun = n;
  while (aun) {
    fn *= 10;
    fn += aun % 10;
    aun /= 10;
  }
  return fn == n;
}
int main() {
  memset(prime, true, sizeof(prime));
  getprime();
  while (~scanf("%lf%lf", &p, &q)) {
    double A = p / q;
    pri = pal = 0;
    for (int i = 1; i < M; i++) {
      pri += prime[i];
      pal += palindromic(i);
      if (pal * p / q >= pri) ans = i;
    }
    printf("%d\n", ans);
  }
  return 0;
}
