#include <bits/stdc++.h>
const int MAX = 1e7 + 1;
using namespace std;
int prime[MAX], pal[MAX];
bool check(int n) {
  int t = n, m = 0;
  while (t) {
    m = 10 * m + t % 10;
    t /= 10;
  }
  return (m == n ? 1 : 0);
}
void solve(int p, int q) {
  double frac = (double(p) * 1.0) / double(q);
  int ans = -1;
  for (int i = int(0); i <= int(1e7); i++) {
    if ((double(prime[i]) * 1.0) <= frac * ((double(pal[i])) * 1.0)) {
      ans = i;
    }
  }
  string s = "Palindromic tree is better than splay tree";
  if (ans == -1)
    cout << s << '\n';
  else
    cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  prime[0] = prime[1] = 1;
  for (int i = 2; i <= sqrt(1e7); i++) {
    if (!prime[i]) {
      int j = i * i;
      while (j <= 1e7) {
        prime[j] = 1;
        j += i;
      }
    }
  }
  prime[0] = 0;
  for (int i = int(1); i <= int(1e7); i++) {
    prime[i] = prime[i - 1] + (1 - prime[i]);
    pal[i] = pal[i - 1] + int(check(i));
  }
  int p, q;
  cin >> p >> q;
  solve(p, q);
  return 0;
}
