#include <bits/stdc++.h>
using namespace std;
int rub[1200000];
int prime[1200000];
void sieve() {
  memset(prime, 0, sizeof prime);
  prime[0] = prime[1] = 0;
  for (int i = 2; i < 1200000; i++) prime[i] = 1;
  for (int i = 4; i < 1200000; i += 2) prime[i] = 0;
  for (int i = 3; (i * i) < 1200000; i += 2)
    if (prime[i])
      for (int j = i * i; j < 1200000; j += i) prime[j] = 0;
  for (int i = 1; i < 1200000; i++) prime[i] += prime[i - 1];
}
int isPal(int a) {
  int tmp = a;
  int rev = 0;
  while (tmp) {
    rev *= 10;
    rev += tmp % 10;
    tmp /= 10;
  }
  return a == rev;
}
void pal() {
  int i, j;
  rub[0] = 0;
  for (i = 1; i < 1200000; i++) rub[i] = rub[i - 1] + isPal(i);
}
int main() {
  long long int p, q;
  scanf("%lld %lld", &p, &q);
  sieve();
  pal();
  int cur = 0;
  for (int i = 1; i < 1200000; i++)
    if (prime[i] * q <= rub[i] * p) cur = i;
  printf("%d\n", cur);
  return 0;
}
