#include <bits/stdc++.h>
using namespace std;
bitset<2001000> bs;
int sieve_size, pc[2001000], palc[2001000];
bool isPal(int n) {
  int n_aux = n;
  int m = 0;
  while (n_aux != 0) {
    m *= 10;
    m += n_aux % 10;
    n_aux /= 10;
  }
  return n == m;
}
void pal() {
  for (int i = 1; i < (int)sieve_size; i++) {
    palc[i] = palc[i - 1];
    if (isPal(i)) palc[i]++;
  }
}
void sieve(long long upperbound) {
  sieve_size = upperbound + 1;
  bs.set();
  bs[0] = bs[1] = false;
  for (long long i = 2; i < sieve_size; i++) {
    pc[i] = pc[i - 1];
    if (bs[i]) {
      pc[i]++;
      for (long long j = i * i; j < sieve_size; j += i) bs[j] = false;
    }
  }
}
int main() {
  sieve(2000100);
  pal();
  int p, q;
  scanf("%d %d", &p, &q);
  int i = 2000010;
  while (q * pc[i] > p * palc[i] && i >= 0) i--;
  if (i < 0)
    printf("Palindromic tree is better than splay tree\n");
  else
    printf("%d\n", i);
}
