#include <bits/stdc++.h>
using namespace std;
int np[1200005], hp[1200005];
bool pri[1200005];
int ishp(int x) {
  int xx = x, nn = 0, num[30];
  while (xx) {
    num[nn++] = xx % 10;
    xx /= 10;
  }
  for (int i = 0; i < nn / 2; i++) {
    if (num[i] != num[nn - 1 - i]) {
      return 0;
    }
  }
  return 1;
}
void init() {
  memset(pri, true, sizeof(pri));
  for (int i = 2; i < 1200005; i++) {
    if (pri[i]) {
      for (int j = i + i; j < 1200005; j += i) {
        pri[j] = false;
      }
    }
  }
  np[0] = np[1] = 0;
  for (int i = 2; i < 1200005; i++) {
    np[i] = np[i - 1];
    if (pri[i]) {
      np[i]++;
    }
  }
  hp[0] = 0;
  for (int i = 1; i < 1200005; i++) {
    hp[i] = hp[i - 1] + ishp(i);
  }
}
int main() {
  int p, q;
  init();
  while (cin >> p >> q) {
    bool flag = true;
    for (int i = 1200005 - 1; i >= 0 && flag; i--) {
      if (q * np[i] <= p * hp[i]) {
        flag = false;
        cout << i << endl;
      }
    }
    if (flag) {
      cout << "Palindromic tree is better than splay tree\n";
    }
  }
  return 0;
}
