#include <bits/stdc++.h>
using namespace std;
const long long lim = 1500000;
long long pr[3001001], pl[3001001], u[3001001];
bool pal(long long x) {
  long long y, l, r;
  string s = "";
  while (x) {
    s += (x % 10) + '0';
    x /= 10;
  }
  l = 0;
  r = s.size() - 1;
  while (s[l] == s[r]) {
    if (r - l <= 1) return true;
    l++;
    r--;
  }
  return false;
}
int main() {
  long long i, j, p, q, l, r, ans = -1, mid;
  for (i = 2; i <= lim; i++) {
    pr[i] = pr[i - 1];
    if (u[i]) continue;
    pr[i]++;
    for (j = i * i; j <= lim; j += i) u[j] = 1;
  }
  for (i = 1; i <= lim; i++) {
    pl[i] = pl[i - 1];
    if (pal(i)) pl[i]++;
  }
  scanf("%I64d%I64d", &p, &q);
  for (i = lim; i >= 0; i--) {
    if (pr[i] * q <= pl[i] * p) {
      ans = i;
      break;
    }
  }
  if (ans == -1)
    printf("Palindromic tree is better than splay tree\n");
  else
    printf("%I64d\n", ans);
}
