#include <bits/stdc++.h>
using namespace std;
const long long N = 10000000 + 5;
long long add_pi[N];
long long add_rub[N];
bool prime[N];
long long p[N], tot;
bool cal(long long n) {
  long long cnt = 0;
  long long arr[50] = {};
  while (n != 0) {
    arr[cnt++] = n % 10;
    n /= 10;
  }
  for (long long i = 0; i < cnt; ++i) {
    if (arr[i] != arr[cnt - 1 - i]) return false;
  }
  return true;
}
void init() {
  for (long long i = 2; i < N; i++) prime[i] = true;
  for (long long i = 2; i < N; i++) {
    if (prime[i]) p[tot++] = i;
    for (long long j = 0; j < tot && i * p[j] < N; j++) {
      prime[i * p[j]] = false;
      if (i % p[j] == 0) break;
    }
  }
  for (long long i = 1; i < N; ++i) {
    add_pi[i] = add_pi[i - 1] + (prime[i] ? 1 : 0);
  }
  for (long long i = 1; i < N; ++i) {
    add_rub[i] = add_rub[i - 1] + (cal(i) ? 1 : 0);
  }
}
int main() {
  init();
  long long p, q;
  bool type = false;
  scanf("%lld%lld", &p, &q);
  for (long long i = 10000000; i >= 0; --i) {
    if (q * add_pi[i] <= p * add_rub[i]) {
      printf("%lld", i);
      type = true;
      break;
    }
  }
  if (!type) {
    printf("Palindromic tree is better than splay tree");
  }
  return 0;
}
