#include <bits/stdc++.h>
using namespace std;
int n = 2000001;
bool prime[2000001];
int pre[2000001], prep[2000001];
bool pal(int x) {
  string second = "";
  while (x) {
    second += x % 10 + '0';
    x /= 10;
  }
  for (int i = 0; i < second.size() / 2; i++) {
    if (second[i] != second[second.size() - i - 1]) return false;
  }
  return true;
}
void solve() {
  fill_n(prime, sizeof prime, true);
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i * i <= n; i++) {
    if (prime[i]) {
      for (int j = i * i; j <= n; j += i) {
        prime[j] = false;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    prep[i] = prep[i - 1] + pal(i);
    pre[i] = pre[i - 1] + prime[i];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  double p, q;
  cin >> p >> q;
  double A = p / q;
  int ans = -1;
  for (int i = n - 1; i >= 0; i--) {
    if (A >= (1.0 * pre[i]) / (1.0 * prep[i])) {
      ans = i;
      break;
    }
  }
  if (ans == -1) {
    cout << "Palindromic tree is better than splay tree" << endl;
  } else
    cout << ans << endl;
  return 0;
}
