#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
int print_value(A title, B val) {
  cout << title << " = " << val << "\n";
  return 1;
}
int break_point() {
  char c;
  while ((c = getchar()) != '\n')
    ;
  return 0;
}
template <typename A>
int logg(A v) {
  cout << v << "\n";
  return 0;
}
void read_intq(int &r) {
  r = 0;
  char c;
  while (1) {
    c = getchar();
    if (c != ' ' && c != '\n') {
      r = c - '0';
      break;
    }
  }
  while (1) {
    c = getchar();
    if (c == ' ' || c == '\n') return;
    r = r * 10 + (c - '0');
  }
}
void read_llq(long long &r) {
  r = 0;
  char c;
  while (1) {
    c = getchar();
    if (c != ' ' && c != '\n') {
      r = c - '0';
      break;
    }
  }
  while (1) {
    c = getchar();
    if (c == ' ' || c == '\n') return;
    r = r * 10 + (c - '0');
  }
}
char get_char() {
  char c;
  while (1) {
    c = getchar();
    if (c != '\n' && c != ' ') return c;
  }
}
void run();
int main() {
  srand(time(NULL));
  do {
    run();
    if (0) {
      0 ? printf("-------------------------------\n") : 0;
      0 ? printf("-------------------------------\n") : 0;
    }
  } while (0);
  return 0;
}
int rev(int n) {
  int t = 0;
  while (n) {
    t = t * 10 + n % 10;
    n /= 10;
  }
  return t;
}
bool ispal(int n) { return n == rev(n); }
long long primes[10000007];
long long pals[10000007];
vector<int> pr;
int lp[10000007];
void run() {
  int p, q;
  scanf("%d%d", &p, &q);
  for (int i = 2; i < 10000007; i++) {
    if (lp[i] == 0) {
      lp[i] = i;
      pr.push_back(i);
      primes[i] = 1;
    }
    primes[i] += primes[i - 1];
    for (int j = 0; j < pr.size() && pr[j] <= lp[i] && i * pr[j] < 10000007;
         j++)
      lp[i * pr[j]] = pr[j];
  }
  int res = -1;
  for (int i = 1; i < 10000007; i++) {
    pals[i] = ispal(i);
    pals[i] += pals[i - 1];
    if (q * primes[i] <= p * pals[i]) res = i;
  }
  if (res == -1)
    printf("Palindromic tree is better than splay tree\n");
  else {
    printf("%d", res);
    putchar('\n');
  }
}
