#include <bits/stdc++.h>
using namespace std;
int prime[10000000 + 5];
int pal(int n) {
  int tot = 0, ara[20];
  while (n) {
    ara[tot++] = n % 10;
    n = n / 10;
  }
  for (int i = 0; i < tot; ++i)
    if (ara[i] != ara[tot - 1 - i]) return 0;
  return 1;
}
int main() {
  long long p, q;
  scanf("%I64d %I64d", &p, &q);
  for (int i = 2; i <= 10000000; ++i)
    if (!prime[i])
      for (int j = 2 * i; j <= 10000000; j += i) prime[j] = 1;
  for (int i = 2; i <= 10000000; ++i) {
    prime[i] = !prime[i];
    prime[i] += prime[i - 1];
  }
  int x = 0, ans = 1;
  for (int i = 1; i <= 10000000; ++i) {
    x += pal(i);
    if (p * x >= q * prime[i]) ans = i;
  }
  printf("%d\n", ans);
  return 0;
}
