#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10;
int num_prime[N], num_pari[N];
bool IsPrime[N];
void init_prime() {
  num_prime[0] = num_prime[1] = 0;
  memset(IsPrime, false, sizeof(IsPrime));
  for (int i = 2; i < N; i++) {
    if (!IsPrime[i]) {
      num_prime[i] = num_prime[i - 1] + 1;
      for (int j = i + i; j < N; j += i) {
        IsPrime[j] = true;
      }
    } else
      num_prime[i] = num_prime[i - 1];
  }
}
bool Judge_pari(int n) {
  int d1[40], num1;
  num1 = 0;
  while (n) {
    d1[num1++] = n % 10;
    n /= 10;
  }
  for (int i = 0; i < num1 / 2; i++)
    if (d1[i] != d1[num1 - 1 - i]) return false;
  return true;
}
void init_pari() {
  num_pari[0] = 0;
  for (int i = 1; i < N; i++)
    if (Judge_pari(i))
      num_pari[i] = num_pari[i - 1] + 1;
    else
      num_pari[i] = num_pari[i - 1];
}
void solve(long long p, long long q) {
  for (int i = N - 1; i >= 0; i--) {
    if (num_prime[i] * q <= num_pari[i] * p) {
      printf("%d\n", i);
      return;
    }
  }
  puts("Palindromic tree is better than splay tree");
}
long long a, b;
int main() {
  init_pari();
  init_prime();
  scanf("%I64d%I64d", &a, &b);
  solve(a, b);
  return 0;
}
