#include <bits/stdc++.h>
using namespace std;
const int OO = 0x3f3f3f3f;
const double eps = (1e-10);
int p, q, ans, pi[10000010], rub[10000010];
vector<int> palis, primes;
bitset<10000010> bs;
void sieve() {
  bs.set();
  bs[0] = bs[1] = 0;
  for (long long i = 2; i <= 10000010; i++)
    if (bs[i]) {
      for (long long j = i * i; j <= 10000010; j += i) bs[j] = 0;
      primes.push_back(i);
    }
}
void constuctPali(int x) {
  string s = to_string(x), t = s;
  reverse(((t).begin()), ((t).end()));
  palis.push_back(stoi(s + t));
  if (((int)((s).size())) == 1)
    palis.push_back(x);
  else {
    t = t.substr(1);
    palis.push_back(stoi(s + t));
  }
}
int main() {
  ios::sync_with_stdio(false);
  cout.precision(7);
  sieve();
  for (int i = (1); i < (int)(10000); ++i) constuctPali(i);
  for (auto& pali : palis)
    if (pali < 10000010) ++rub[pali];
  for (int i = (1); i < (int)(10000010); ++i) rub[i] += rub[i - 1];
  for (auto& prime : primes)
    if (prime < 10000010) ++pi[prime];
  for (int i = (1); i < (int)(10000010); ++i) pi[i] += pi[i - 1];
  cin >> p >> q;
  for (int i = 0; i < (int)(10000010); ++i)
    if (1LL * pi[i] * q <= 1LL * p * rub[i]) ans = max(ans, i);
  cout << ans << '\n';
  return 0;
}
