#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9, maxn = (int)1e5 + 1;
const double eps = (double)1e-8;
const int mod = (int)1000000007;
int s1, s2, k, a[102], n, p[2000005], t1, t2;
double p1, q, x;
int rub(int x) {
  k = 0;
  while (x > 0) {
    k++;
    a[k] = x % 10;
    x /= 10;
  }
  for (int i = (1); i <= (k / 2); i++)
    if (a[i] != a[k - i + 1]) return 0;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  n = 2000000;
  s1 = 0;
  s2 = 0;
  memset((p), 0, sizeof(p));
  ;
  p[1] = 1;
  for (int i = (2); i <= (n); i++) {
    if (p[i]) continue;
    for (long long j = (long long)i * (long long)i; j <= n; j += (long long)i)
      p[j] = 1;
  }
  cin >> p1 >> q;
  x = (double)p1 / (double)q;
  int ans = -1;
  for (int i = (1); i <= (n); i++) {
    t1 = !p[i];
    t2 = rub(i);
    s1 += t1;
    s2 += t2;
    if ((double)q * (double)s1 <= (double)p1 * (double)s2) {
      ans = max(ans, i);
    }
  }
  if (ans == -1) {
    cout << "Palindromic tree is better than splay tree";
  } else {
    cout << ans;
  }
  return 0;
}
