#include <bits/stdc++.h>
using namespace std;
int p, q;
vector<int> pr;
int dd[1300005], sl[1200005];
int check(int x) {
  int vt = upper_bound(pr.begin(), pr.end(), x) - pr.begin();
  return ((vt - 1) * q <= p * sl[x]);
}
int c(int x) {
  string st;
  while (x) {
    st += (x % 10) + '0';
    x /= 10;
  }
  int l = st.size();
  st = '*' + st;
  for (int i = 1; i <= l / 2; i++)
    if (st[i] != st[l - i + 1]) return 0;
  return 1;
}
void sang() {
  for (int i = 2; i <= 1200000; i++)
    if (!dd[i]) {
      pr.push_back(i);
      for (int j = i + i; j <= 1200000; j += i) dd[j] = 1;
    }
  for (int i = 1; i <= 1200000; i++) sl[i] = sl[i - 1] + c(i);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> p >> q;
  pr.push_back(-1);
  sang();
  int res = -1;
  for (int i = 1; i <= 1200000; i++)
    if (check(i)) res = i;
  if (res == -1)
    cout << "Palindromic tree is better than splay tree";
  else
    cout << res;
  return 0;
}
