#include <bits/stdc++.h>
using namespace std;
int prime[2000001], pal[2000001], pr[2000001];
bool pall(int i) {
  string x = "";
  while (i) {
    x += (char)(i % 10 + '0');
    i /= 10;
  }
  for (int j = 0; j < x.size() / 2; ++j)
    if (x[j] != x[x.size() - j - 1]) return false;
  return true;
}
int main() {
  float p, q;
  cin >> p >> q;
  p = p / q;
  prime[1] = 1;
  for (int i = 2; i < 2000000; ++i)
    if (!prime[i])
      for (int j = i + i; j < 2000000; j += i) prime[j] = 1;
  for (int i = 1; i < 2000000; ++i) pr[i] = pr[i - 1], pr[i] += !prime[i];
  for (int i = 1; i < 2000000; ++i) {
    pal[i] = pal[i - 1];
    if (pall(i)) ++pal[i];
  }
  for (int ans = 1999999; ans >= 1; --ans) {
    if ((float)(pr[ans]) <= p * (float)(pal[ans])) {
      cout << ans << endl;
      return 0;
    }
  }
}
