#include <bits/stdc++.h>
using namespace std;
long long ara[2000010];
long long cum1[2000010];
void sieve() {
  long long i, j;
  for (i = 0; i < 2000010; i++) {
    ara[i] = 0;
  }
  for (i = 4; i < 2000010; i += 2) {
    ara[i] = 1;
  }
  ara[0] = 1;
  ara[1] = 1;
  for (i = 3; i < 1420; i += 2) {
    if (ara[i] == 0) {
      for (j = i * i; j <= 2000010; j += (2 * i)) {
        ara[j] = 1;
      }
    }
  }
  for (int i = 1; i <= 2e6; i++) {
    cum1[i] = cum1[i - 1] + !ara[i];
  }
}
int cum2[2001000];
bool chk(string s) {
  int sz = s.size() / 2;
  int j = s.size() - 1;
  for (int i = 0; i < sz; i++) {
    if (s[i] != s[j]) return 0;
    j--;
  }
  return 1;
}
int main() {
  sieve();
  cum2[0] = 0;
  for (int i = 1; i <= 2e6; i++) {
    string s = "";
    if (i == 0) s = "0";
    int v = i;
    while (v != 0) {
      int a = v % 10;
      s += (a + '0');
      v /= 10;
    }
    reverse(s.begin(), s.end());
    if (chk(s)) {
      cum2[i] = cum2[i - 1] + 1;
    } else
      cum2[i] = cum2[i - 1];
  }
  int p, q;
  cin >> p >> q;
  int ans = -1;
  for (int i = 1; i <= 2e6; i++) {
    long long v1 = (cum2[i] * p) / q;
    if (v1 >= cum1[i]) ans = i;
  }
  if (ans == -1)
    cout << "Palindromic tree is better than splay tree" << endl;
  else
    cout << ans << endl;
}
