#include <bits/stdc++.h>
using namespace std;
bool status[2000005];
vector<int> pal, prime;
bool check_palin(int n) {
  if (n < 10) return true;
  vector<int> temp;
  int a, i, j;
  while (n) {
    a = n % 10;
    temp.push_back(a);
    n /= 10;
  }
  i = 0, j = temp.size() - 1;
  while (i < j) {
    if (temp[i] != temp[j]) {
      return false;
    }
    i++, j--;
  }
  return true;
}
int main() {
  int i, j, p, q, si;
  si = int(sqrt((double)2000005));
  for (i = 3; i <= si; i += 2) {
    for (j = i * i; j <= 2000005; j += i + i) {
      status[j] = true;
    }
  }
  status[2] = false;
  status[1] = true;
  scanf("%d %d", &p, &q);
  int ans = -1, prime_num = 0, pal_num = 0;
  for (i = 1; i <= 2000005; i++) {
    if (check_palin(i)) {
      pal_num++;
    }
    if ((!status[i] && i % 2 && i != 1) || (i == 2)) {
      prime_num++;
    }
    if (q * prime_num <= p * pal_num) {
      ans = i;
    }
  }
  if (ans == -1)
    printf("Palindromic tree is better than splay tree\n");
  else
    printf("%d\n", ans);
  return 0;
}
