#include <bits/stdc++.h>
using namespace std;
const int n = 1179859;
int p, q, pri[n], pal[n], ar[10];
bool used[n];
int main() {
  scanf("%d%d", &p, &q);
  for (int i = 2, cur = 0; i < n; i++) {
    if (!used[i]) {
      cur++;
      for (int j = 1; j * i < n; j++) used[j * i] = 1;
    }
    pri[i] = cur;
  }
  bool flag;
  for (int i = 1, x, bas, cur = 0; i < n; i++) {
    bas = 0;
    x = i;
    while (x) {
      ar[++bas] = x % 10;
      x /= 10;
    }
    flag = 1;
    for (int j = 1; j <= bas; j++)
      if (ar[j] != ar[bas - j + 1]) {
        flag = 0;
        break;
      }
    cur += flag;
    pal[i] = cur;
  }
  double coe = (double)p / q;
  for (int i = n - 1; i; i--)
    if (pri[i] <= pal[i] * coe) {
      printf("%d\n", i);
      return 0;
    }
  puts("Palindromic tree is better than splay tree");
  return 0;
}
