#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000000;
bool flag[maxn];
vector<int> prime;
int prime_cnt[maxn];
void get_prime() {
  for (int i = 2; i < maxn; i++) {
    if (!flag[i]) {
      prime.push_back(i);
    }
    for (int j = 0; j < prime.size() && i * prime[j] < maxn; j++) {
      flag[i * prime[j]] = true;
    }
  }
  for (int j = 2; j < maxn; j++) {
    prime_cnt[j] = prime_cnt[j - 1];
    if (!flag[j]) prime_cnt[j]++;
  }
}
int c[10];
bool judge(int n) {
  int idx = 0;
  while (n) {
    c[idx] = n % 10;
    n /= 10;
    idx++;
  }
  for (int i = 0, j = idx - 1; i < j; i++, j--) {
    if (c[i] != c[j]) return false;
  }
  return true;
}
int par_cnt[maxn];
void get_par() {
  for (int i = 1; i < maxn; i++) {
    if (judge(i)) par_cnt[i] = 1;
  }
  for (int i = 1; i < maxn; i++) {
    par_cnt[i] += par_cnt[i - 1];
  }
}
int main() {
  get_prime();
  get_par();
  int p, q;
  scanf("%d%d", &p, &q);
  int ans = -1;
  for (int i = 1; i < maxn; i++) {
    if (q * prime_cnt[i] <= p * par_cnt[i]) {
      ans = i;
    }
  }
  if (ans == -1) {
    printf("Palindromic tree is better than splay tree\n");
  } else {
    printf("%d\n", ans);
  }
}
