#include <bits/stdc++.h>
using namespace std;
int p, q;
bool prime[10000005];
int pal[10000005];
int sucnt[10000005];
double A;
inline void make_prime() {
  memset(prime, 1, sizeof(prime));
  prime[0] = false;
  prime[1] = false;
  long long N = 10000000;
  for (long long i = 2; i < N; i++)
    if (prime[i]) {
      for (long long k = i * i; k < N; k += i) prime[k] = false;
    }
  return;
}
inline bool judge(int num) {
  int temp = num;
  int sum = 0;
  while (num) {
    sum = sum * 10 + num % 10;
    num /= 10;
  }
  if (temp == sum) return 1;
  return 0;
}
inline void huiwen() {
  int i;
  pal[0] = 0;
  for (i = 1; i <= 10000000; i++) {
    if (judge(i))
      pal[i] = pal[i - 1] + 1;
    else
      pal[i] = pal[i - 1];
  }
}
inline void cal() {
  for (int i = 2; i <= 10000000; i++) {
    if (prime[i])
      sucnt[i] = sucnt[i - 1] + 1;
    else
      sucnt[i] = sucnt[i - 1];
  }
}
int main() {
  scanf("%d%d", &p, &q);
  A = p * 1.0 / q * 1.0;
  make_prime();
  huiwen();
  cal();
  for (int i = 10000000; i >= 0; i--) {
    double tt = double(sucnt[i]) * 1.0;
    double ttt = double(pal[i]) * 1.0;
    if ((tt - A * ttt) < 0 || ((tt - A * ttt) < 1e-6)) {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("Palindromic tree is better than splay tree\n");
  return 0;
}
