#include <bits/stdc++.h>
using namespace std;
vector<int> primes;
const int N = 2000000;
bool vis[N + 10] = {};
vector<int> plad;
int me(int n) {
  return upper_bound(plad.begin(), plad.end(), n) - plad.begin();
}
int tell(int n) {
  return upper_bound(primes.begin(), primes.end(), n) - primes.begin();
}
bool isPalin(int r) {
  int x = r, a = 0;
  while (r) {
    a *= 10;
    a += (r % 10);
    r /= 10;
  }
  return x == a;
}
int main() {
  int p, q;
  cin >> p >> q;
  for (int i = 2; i <= N; i++) {
    if (!vis[i]) {
      for (int j = i; j <= N; j += i) {
        vis[j] = true;
      }
      primes.push_back(i);
    }
  }
  for (int i = 1; i <= N; i++) {
    if (isPalin(i)) {
      plad.push_back(i);
    }
  }
  int res = -1;
  for (int i = 0; i <= N; i++) {
    if (tell(i) * q * 1LL <= me(i) * p * 1LL) {
      res = max(res, i);
    }
  }
  if (res == -1)
    cout << "Palindromic tree is better than splay tree" << endl;
  else
    cout << res << endl;
  return 0;
}
