#include <bits/stdc++.h>
using namespace std;
const int maxn = 10000010;
int prime[maxn];
int palins[maxn];
int primes[maxn];
bool palin(int x) {
  int x2 = x;
  int rev = 0;
  while (x) {
    rev = rev * 10 + x % 10;
    x /= 10;
  }
  return rev == x2;
}
int main() {
  prime[2] = 1;
  for (int i = 3; i <= 10000000; i += 2) prime[i] = 1;
  for (int i = 3; i * i <= 10000000; i += 2) {
    if (prime[i]) {
      for (int j = i * i; j <= 10000000; j += i) prime[j] = 0;
    }
  }
  palins[1] = 1;
  for (int i = 2; i <= 10000000; i++) {
    palins[i] = palins[i - 1] + (int)palin(i);
    primes[i] = primes[i - 1] + (int)prime[i];
  }
  int p, q;
  scanf("%d%d", &p, &q);
  int N = -1;
  for (int i = 1; i <= 1200000; i++) {
    if ((long long)primes[i] * q <= (long long)palins[i] * p) {
      if (i > N) N = i;
    }
  }
  if (N != -1)
    printf("%d", N);
  else
    printf("Palindromic tree is better than splay tree");
  return 0;
}
