#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 10;
int n;
double p, q;
int prime[maxn];
void siev() {
  for (int i = 2; i < maxn; i++) {
    if (!prime[i]) continue;
    for (int j = i + i; j < maxn; j += i) {
      prime[j] = 0;
    }
  }
}
int is_palindrome(int num) {
  vector<int> v;
  while (num) {
    v.push_back(num % 10);
    num = num / 10;
  }
  for (int i = 0; i < v.size() / 2; i++)
    if (v[i] != v[v.size() - 1 - i]) return false;
  return true;
}
int main() {
  for (int i = 2; i < maxn; i++) prime[i] = 1;
  siev();
  cin >> p >> q;
  int pals = 0, primes = 0, ans = -1;
  for (int i = 1; i <= maxn; i++) {
    primes += prime[i];
    pals += is_palindrome(i);
    if (primes <= (p * pals) / q) ans = i;
  }
  cout << ans;
}
