#include <bits/stdc++.h>
using namespace std;
void SolveA() {
  long long p;
  long long q;
  cin >> p >> q;
  size_t vSize = 10000000;
  vector<int> isPrime(vSize, 1);
  isPrime[0] = isPrime[1] = 0;
  for (size_t i = 2; i < vSize; ++i) {
    if (isPrime[i]) {
      size_t cur = 2 * i;
      while (cur < vSize) {
        isPrime[cur] = 0;
        cur += i;
      }
    }
  }
  vector<size_t> d(10, 0);
  size_t nd = 1;
  long long nPrime = 0;
  long long nPal = 0;
  size_t ans = 0;
  for (size_t i = 1; i < vSize; ++i) {
    if (isPrime[i]) ++nPrime;
    size_t curD = 0;
    size_t carry = 1;
    while (curD < nd || carry > 0) {
      size_t newD = (carry + d[curD]) % 10;
      carry = (carry + d[curD]) / 10;
      d[curD] = newD;
      ++curD;
    }
    nd = max(curD, nd);
    bool pal = true;
    for (size_t j = 0; j < nd / 2; ++j) pal = pal && (d[j] == d[nd - j - 1]);
    if (pal) ++nPal;
    if (q * nPrime <= p * nPal) ans = i;
  }
  if (ans == 0)
    cout << "Palindromic tree is better than splay tree";
  else
    cout << ans;
}
int main() {
  SolveA();
  return 0;
}
