#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * (b / (gcd(a, b))); }
long long primes[10000000 + 1];
long long palns[10000000 + 1];
int P, Q;
bool isPrime[10000000 + 1];
static void sieve(long N) {
  memset(isPrime, true, sizeof(isPrime));
  isPrime[1] = false;
  isPrime[0] = false;
  for (int i = 2; i * i <= N; i++) {
    if (isPrime[i]) {
      for (int j = i * 2; j <= N; j += i) {
        isPrime[j] = false;
      }
    }
  }
}
bool isPalin(int x) {
  if (x < 0) return false;
  int div = 1;
  while (x / div >= 10) {
    div *= 10;
  }
  while (x != 0) {
    int l = x / div;
    int r = x % 10;
    if (l != r) return false;
    x = (x % div) / 10;
    div /= 100;
  }
  return true;
}
int main() {
  sieve(10000000 + 1);
  memset(palns, 0, sizeof(palns));
  memset(primes, 0, sizeof(primes));
  std::ios_base::sync_with_stdio(false);
  cin >> P >> Q;
  palns[0] = 0;
  primes[0] = 0;
  for (int i = 1; i <= (int)10000000; i++) {
    palns[i] = palns[i - 1];
    primes[i] = primes[i - 1];
    if (isPalin(i)) palns[i]++;
    if (isPrime[i]) primes[i]++;
  }
  int mx = -1;
  for (int i = 1; i <= (int)10000000; i++) {
    if ((long long)primes[i] * Q <= (long long)palns[i] * P) mx = max(mx, i);
  }
  mx == -1 ? cout << "Palindromic tree is better than splay tree" : cout << mx;
  cout << "\n";
}
