#include <bits/stdc++.h>
using namespace std;
double p, q;
int isPrime[2000005], prime_table[2000005], cnt, ans;
vector<int> palin;
void build() {
  cnt = 0;
  memset(isPrime, -1, sizeof(isPrime));
  for (int i = 2; i <= 2000000; i++) {
    if (isPrime[i] == 0) continue;
    isPrime[i] = 1;
    for (int j = 2; j < sqrt(i); j++) {
      if (i % j == 0) {
        isPrime[i] = 0;
        break;
      }
    }
    if (isPrime[i]) {
      prime_table[cnt++] = i;
      for (int j = 2 * i; j <= 2000000; j += i) {
        isPrime[j] = 0;
      }
    }
  }
  palin.clear();
  for (int i = 1; i <= 9; i++) palin.push_back(i);
  for (int i = 1; i <= 9; i++) palin.push_back(i * 10 + i);
  for (int i = 1; i <= 9; i++)
    for (int j = 0; j <= 9; j++) palin.push_back(i * 100 + j * 10 + i);
  for (int i = 1; i <= 9; i++)
    for (int j = 0; j <= 9; j++)
      palin.push_back(i * 1000 + j * 100 + j * 10 + i);
  for (int i = 1; i <= 9; i++)
    for (int j = 0; j <= 9; j++)
      for (int k = 0; k <= 9; k++)
        palin.push_back(i * 10000 + j * 1000 + k * 100 + j * 10 + i);
  for (int i = 1; i <= 9; i++)
    for (int j = 0; j <= 9; j++)
      for (int k = 0; k <= 9; k++)
        palin.push_back(i * 100000 + j * 10000 + k * 1000 + k * 100 + j * 10 +
                        i);
  for (int i = 1; i <= 9; i++)
    for (int j = 0; j <= 9; j++)
      for (int k = 0; k <= 9; k++)
        for (int l = 0; l <= 9; l++)
          palin.push_back(i * 1000000 + j * 100000 + k * 10000 + l * 1000 +
                          k * 100 + j * 10 + i);
}
int main(void) {
  build();
  vector<int>::iterator low, up;
  while (2 == scanf("%lf %lf", &p, &q)) {
    ans = -1;
    for (int i = 0; i < cnt; i++) {
      int target = prime_table[i] - 1;
      low = lower_bound(palin.begin(), palin.end(), target);
      int n = low - palin.begin();
      if (palin[n] == target) n++;
      if ((double)i <= (p / q) * (double)n) ans = target;
    }
    if (ans > 0)
      printf("%d\n", ans);
    else
      printf("Palindromic tree is better than splay tree\n");
  }
  return 0;
}
