#include <bits/stdc++.h>
using namespace std;
int a[1200005];
double b[1200005];
double a1[1200005];
int main() {
  a[0] = a[1] = 1;
  for (int i = 2; i <= 1200000; i++) {
    if (!a[i]) {
      for (int j = i * 2; j <= 1200000; j += i) a[j] = 1;
    }
  }
  for (int i = 1; i <= 1200000; i++) {
    a1[i] = a1[i - 1];
    if (!a[i]) a1[i]++;
  }
  for (int i = 1; i <= 1200000; i++) {
    int t = i;
    int s[100];
    int x = 0;
    int flag = 0;
    b[i] = b[i - 1];
    while (t) {
      s[x++] = t % 10;
      t /= 10;
    }
    for (int j = 0; j < x; j++) {
      if (s[j] != s[x - 1 - j]) {
        flag = 1;
        break;
      }
    }
    if (!flag) b[i]++;
  }
  double p, q;
  cin >> p >> q;
  p = p / q;
  int flag = 0;
  for (int i = 1; i <= 1200000; i++) {
    if (p >= a1[i] / b[i]) {
      flag = i;
    }
  }
  if (flag)
    printf("%d\n", flag);
  else
    printf("Palindromic tree is better than splay tree\n");
}
