#include <bits/stdc++.h>
using namespace std;
int p, q;
int f[5000004], rub[5000004];
bool sh[5000004];
void shai(int N) {
  memset(sh, 0, sizeof(sh));
  sh[1] = 1;
  for (int i = 1; i <= N; i++) {
    if (!sh[i])
      for (int j = i + i; j <= N; j += i) sh[j] = 1;
  }
}
bool kat(int x) {
  int p = x, t[14], cnt = 0;
  while (p) t[++cnt] = p % 10, p /= 10;
  int l = 1, r = cnt;
  while (l <= r) {
    if (t[l] != t[r]) return false;
    ++l;
    --r;
  }
  return true;
}
int main() {
  cin >> p >> q;
  shai(5000000);
  f[0] = f[1] = 0;
  rub[1] = 1;
  for (int i = 2; i <= 5000000; i++) {
    if (!sh[i])
      f[i] = f[i - 1] + 1;
    else
      f[i] = f[i - 1];
    if (kat(i))
      rub[i] = rub[i - 1] + 1;
    else
      rub[i] = rub[i - 1];
  }
  for (int i = 5000000; i >= 1; i--) {
    if ((long long)f[i] * (long long)q <= (long long)rub[i] * (long long)p)
      return printf("%d\n", i), 0;
  }
  cout << "Palindromic tree is better than splay tree" << endl;
  return 0;
}
