#include <bits/stdc++.h>
using namespace std;
int A[2000001], F[2000001], C[2000001];
char S[20];
void Solve() {
  memset(F, 0, sizeof(F));
  A[0] = A[1] = 0;
  for (int i = 2; i <= 2000001; ++i) {
    if (!F[i])
      F[++F[0]] = i, A[i] = A[i - 1] + 1;
    else
      A[i] = A[i - 1];
    for (int j = 1; j <= F[0] && F[j] <= 2000001 / i; ++j) {
      F[i * F[j]] = 1;
      if (i % F[j] == 0) break;
    }
  }
}
bool judge(int a) {
  int t = 0;
  while (a) {
    S[t++] = a % 10;
    a /= 10;
  }
  for (int i = 0; 2 * i < t; ++i)
    if (S[i] != S[t - 1 - i]) return 0;
  return 1;
}
void getC() {
  C[0] = 0;
  for (int i = 1; i < 2000001; ++i)
    if (judge(i))
      C[i] = C[i - 1] + 1;
    else
      C[i] = C[i - 1];
}
int main() {
  long long p, q;
  Solve();
  getC();
  cin >> p >> q;
  int n = 2000000;
  while (n > 0 && q * A[n] > p * C[n]) n--;
  if (n == 0)
    cout << "Palindromic tree is better than splay tree" << endl;
  else
    cout << n << endl;
  return 0;
}
