#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const long double EPS = 1e-8;
const long double PI = acos(-1.0);
const int MAXN = 2e6;
bool sieve[MAXN + 1];
bool is_palindromic(int n) {
  char s[10];
  sprintf(s, "%d", n);
  for (int i = 0, j = strlen(s) - 1; j >= 0; ++i, --j)
    if (s[i] != s[j]) return false;
  return true;
}
void run() {
  int i, j;
  memset(sieve, 1, sizeof(sieve));
  sieve[1] = false;
  for (i = 2; i * i <= MAXN; ++i)
    for (j = i * i; j <= MAXN; j += i) sieve[j] = false;
  int p, q;
  scanf("%d%d", &p, &q);
  int n, ans = 2e9;
  long long pi = 0, rub = 0;
  for (n = 1; n <= MAXN; ++n) {
    pi += sieve[n];
    rub += is_palindromic(n);
    if (q * pi <= p * rub) ans = n;
  }
  printf("%d\n", ans);
}
int main() {
  run();
  return 0;
}
