#include <bits/stdc++.h>
using namespace std;
int prime[10000005], pal[10000005];
bool isPal(int n) {
  vector<int> digits;
  while (n > 0) {
    digits.push_back(n % 10);
    n /= 10;
  }
  int len = digits.size();
  for (int i = 0; i < len; i++) {
    if (digits[i] != digits[len - 1 - i]) return false;
  }
  return true;
}
int main() {
  fill(prime, prime + 10000000, 1);
  prime[1] = 0;
  for (int i = 2; i * i <= 2000000; i++) {
    if (prime[i]) {
      int pro = i * i;
      while (pro <= 2000000) {
        prime[pro] = 0;
        pro += i;
      }
    }
  }
  for (int i = 1; i <= 2000000; i++) {
    if (isPal(i))
      pal[i] = 1;
    else
      pal[i] = 0;
  }
  int p, q, primeCnt = 0, palCnt = 0, ans;
  cin >> p >> q;
  for (int i = 1; i <= 2000000; i++) {
    if (prime[i]) {
      primeCnt++;
    }
    if (pal[i]) palCnt++;
    if (q * primeCnt <= p * palCnt) {
      ans = i;
    }
  }
  if (ans != -1)
    cout << ans << endl;
  else
    cout << "Palindromic tree is better than splay tree\n";
  return 0;
}
