#include <bits/stdc++.h>
using namespace std;
const int N = 2000000 + 10;
int prime[N], totPrimes, notPrime[N];
int p, q;
int calcPi(int n) { return upper_bound(prime, prime + totPrimes, n) - prime; }
int isPalindromic(int n) {
  static char s[10];
  static int l;
  for (l = 0; n > 0; n /= 10) {
    s[l++] = n % 10;
  }
  for (int i = 0; i < l; ++i) {
    if (s[i] != s[l - 1 - i]) {
      return 0;
    }
  }
  return 1;
}
int main() {
  for (int i = 2; i < N; ++i) {
    if (!notPrime[i]) {
      prime[totPrimes++] = i;
      for (int j = i + i; j < N; j += i) {
        notPrime[j] = 1;
      }
    }
  }
  cin >> p >> q;
  int ans, rub = 0;
  for (int i = 1; i < N; ++i) {
    if (isPalindromic(i)) {
      ++rub;
    }
    if (calcPi(i) * q <= p * rub) {
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}
