#include <bits/stdc++.h>
using namespace std;
const int LIMIT = 1e7;
int prime[LIMIT], palin[LIMIT];
int pr[LIMIT], pa[LIMIT];
int cnt_dig(int x) {
  if (x == 0)
    return 1;
  else {
    int ans = 0;
    while (x > 0) {
      x /= 10;
      ans++;
    }
    return ans;
  }
}
int main() {
  int n = 4 * 1e6, dg, fl, t;
  stack<int> st;
  for (int i = 0; i < n; i++) prime[i] = true;
  prime[0] = prime[1] = false;
  prime[2] = true;
  for (long long i = 2; i < n; i++) {
    if (prime[i] == true) {
      for (long long j = i * i; j < n; j += i) prime[j] = false;
    }
  }
  for (int i = 0; i < n; i++) {
    dg = cnt_dig(i);
    t = i;
    if (dg == 1)
      palin[i] = true;
    else {
      fl = 0;
      if (dg & 1) {
        for (int j = 0; j < dg / 2; j++) {
          st.push(t % 10);
          t = t / 10;
        }
        t = t / 10;
        for (int j = 0; j < dg / 2; j++) {
          if (t % 10 == st.top()) {
            t = t / 10;
            st.pop();
          } else {
            fl = 1;
            break;
          }
        }
        st.empty();
      } else {
        for (int j = 0; j < dg / 2; j++) {
          st.push(t % 10);
          t = t / 10;
        }
        for (int j = 0; j < dg / 2; j++) {
          if (t % 10 == st.top()) {
            t = t / 10;
            st.pop();
          } else {
            fl = 1;
            break;
          }
        }
        st.empty();
      }
      if (fl == 0)
        palin[i] = true;
      else
        palin[i] = false;
    }
  }
  for (int i = 1; i < n; i++) {
    pr[i] = prime[i] + pr[i - 1];
    pa[i] = palin[i] + pa[i - 1];
  }
  double p, q;
  cin >> p >> q;
  int l = 1, r = n - 1;
  t = 0;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    if (pr[i] <= double(pa[i] * (p / q))) ans = i;
  }
  cout << ans << endl;
}
