#include <bits/stdc++.h>
using namespace std;
const int N = 10000000;
float a[N], b[N];
bool isp[N];
string ppf;
bool isPol(string q) {
  int s = q.size(), p = s - 1, n1;
  n1 = (s % 2 == 0 ? s / 2 - 1 : s / 2);
  for (int i = 0; i <= n1; i++) {
    if (q[i] != q[p]) return 0;
    p--;
  }
  return 1;
}
int main() {
  int pp = 0;
  for (int i = 2; i <= 2000000; i++) {
    if (isp[i] == 0) {
      pp++;
      for (int j = i + i; j <= 2000000; j += i) isp[j] = 1;
    }
    a[i] = pp;
  }
  pp = 0;
  for (int i = 1; i <= 2000000; i++) {
    string ppq = ppf;
    int bn = i;
    while (bn) {
      ppq += bn % 10 + '0';
      bn /= 10;
    }
    reverse(ppq.begin(), ppq.end());
    if (isPol(ppq)) pp++;
    b[i] = pp;
  }
  float p, q, A;
  cin >> p >> q;
  A = p / q;
  int ppp = -1;
  for (int i = 1; i <= 2000000; i++) {
    if (a[i] <= A * b[i]) ppp = i;
  }
  if (ppp != -1)
    cout << ppp;
  else
    cout << "Palindromic tree is better than splay tree\n";
  return 0;
}
