#include <bits/stdc++.h>
using namespace std;
vector<long long> getprimes(long long n) {
  vector<long long> sieve(n);
  for (long long i = 2;; i++) {
    if (i > sieve.size()) break;
    if (sieve[i] != 0) continue;
    for (long long j = 2;; j++) {
      if (i * j > sieve.size()) break;
      sieve[i * j] = 1;
    }
  }
  vector<long long> ans;
  for (long long i = 2; i < sieve.size(); i++) {
    if (sieve[i] == 0) ans.push_back(i);
  }
  return ans;
}
bool isPalin(long long n) {
  string str1 = to_string(n);
  string str2 = str1;
  reverse(str1.begin(), str1.end());
  if (str2 == str1) return true;
  return false;
}
int32_t main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  vector<long long> primes = getprimes(1179880);
  map<long long, long long> m;
  for (long long i = 0; i < primes.size(); i++) m[primes[i]]++;
  long long p, q;
  cin >> p >> q;
  long long prime = 0;
  long long palin = 0;
  long long ans = 0;
  for (long long i = 1; i < 1179880; i++) {
    if (m[i] > 0) prime++;
    if (isPalin(i)) {
      palin++;
    }
    if (p * palin >= q * prime) {
      ans = i;
    }
  }
  cout << ans << "\n";
}
