#include <bits/stdc++.h>
using namespace std;
const int LIMIT = 2e6;
int f[LIMIT + 1] = {0}, g[LIMIT + 1] = {0};
bool isP(int n) {
  if (n == 1) return false;
  if (n == 2) return true;
  if (!(n % 2)) return false;
  for (int i = 3; i * i <= n; i += 2)
    if (!(n % i)) return false;
  return true;
}
bool isPar(int n) {
  int l[10], i = 0;
  while (n) {
    l[i++] = n % 10;
    n /= 10;
  }
  int a = 0;
  i--;
  while (a < i) {
    if (l[a] != l[i]) return false;
    a++;
    i--;
  }
  return true;
}
int main() {
  int p, q;
  for (int i = 1; i <= LIMIT; i++) {
    f[i] = f[i - 1];
    g[i] = g[i - 1];
    if (isP(i)) f[i]++;
    if (isPar(i)) g[i]++;
  }
  scanf("%d%d", &p, &q);
  int max = 0;
  for (int i = 1; i <= LIMIT; i++)
    if (q * f[i] <= p * g[i]) max = i;
  if (max)
    printf("%d\n", max);
  else
    printf("Palindromic tree is better than splay tree\n");
  return 0;
}
