#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
using namespace std;
void fail() {
  cout << "-1\n";
  exit(0);
}
const long long N = 1e7 + 5;
long long dp[N], p, q, isp[N], primes[N];
long long fr(long long x) {
  while (x / 10) {
    x /= 10;
  }
  return x;
}
long long chk(long long num) {
  string s = to_string(num);
  long long no = s.length();
  for (long long i = 0; i <= (s.length()) / 2; i++) {
    if (s[i] != s[no - i - 1]) {
      return false;
    }
  }
  return true;
}
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> p >> q;
  for (long long i = 2; i < N; i++) {
    if (isp[i]) continue;
    for (long long j = 2 * i; j < N; j += i) isp[j] = 1;
  }
  dp[1] = 1;
  for (long long i = 2; i < N; i++) {
    primes[i] = primes[i - 1];
    primes[i] += (isp[i] == 0);
    dp[i] = dp[i - 1];
    dp[i] += chk(i);
  }
  long long ans = 0;
  for (long long i = N - 1; i >= 1; i--) {
    long long pi = primes[i], rub = dp[i];
    if (pi * q <= rub * p) {
      cout << i << '\n';
      ans = 1;
      break;
    }
  }
  if (!ans) cout << "Palindromic tree is better than splay tree\n";
  return 0;
}
