#include <bits/stdc++.h>
using namespace std;
void doh() {
  cout << "Palindromic tree is better than splay tree\n";
  exit(0);
}
const int maxn = 1e+7;
bool prime[maxn];
vector<int> pr;
vector<int> r;
vector<int> erat() {
  prime[0] = prime[1] = true;
  for (long long i = 2; i < maxn; i++) {
    if (!prime[i]) {
      for (long long j = i * i; j < maxn; j += i) {
        prime[j] = true;
      }
    }
  }
  vector<int> ans;
  for (int i = 0; i < maxn; ++i)
    if (!prime[i]) ans.push_back(i);
  return ans;
}
bool check(int val) {
  int cur = 0;
  int buf = val;
  while (buf) {
    cur = cur * 10 + buf % 10;
    buf /= 10;
  }
  return cur == val;
}
vector<int> rub() {
  vector<int> ans;
  for (int i = 0; i < maxn; ++i)
    if (check(i) && i) ans.push_back(i);
  return ans;
}
void solve(double p, double q) {
  pr = erat();
  r = rub();
  int ans = -1;
  long long pointer1 = 0;
  long long pointer2 = 0;
  for (int i = 0; i < maxn; ++i) {
    while (pointer1 < ((int)pr.size()) && pr[pointer1] <= i) pointer1++;
    while (pointer2 < ((int)r.size()) && r[pointer2] <= i) pointer2++;
    long long sz1 = pointer1 * q;
    long long sz2 = pointer2 * p;
    if (sz1 <= sz2) ans = i;
  }
  if (ans == -1) {
    doh();
  }
  cout << ans << "\n";
}
int main() {
  double p, q;
  cin >> p >> q;
  solve(p, q);
  return 0;
}
