#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1201000;
bool palin(int x) {
  vector<int> a, b;
  while (x > 0) {
    a.push_back(x % 10);
    b.push_back(x % 10);
    x /= 10;
  }
  reverse(a.begin(), a.end());
  for (int i = 0; i < (int)a.size(); ++i)
    if (a[i] != b[i]) return false;
  return true;
}
bool prime[MAXN];
void init() {
  const int NSQRT = (int)sqrt(MAXN);
  for (int i = 3; i < NSQRT; i += 2) {
    if (prime[i]) continue;
    for (int j = i * i; j < MAXN; j += i) prime[j] = 1;
  }
  for (int i = 0; i < MAXN; ++i) {
    prime[i] ^= 1;
    if ((i & 1) == 0) prime[i] = 0;
  }
  prime[0] = prime[1] = 0;
  prime[2] = 1;
}
int pi[MAXN];
int rub[MAXN];
int main(void) {
  init();
  for (int i = 1; i < MAXN; ++i) {
    pi[i] = pi[i - 1];
    rub[i] = rub[i - 1];
    if (prime[i]) ++pi[i];
    if (palin(i)) ++rub[i];
  }
  int p, q;
  scanf("%d%d", &p, &q);
  for (int i = MAXN - 1; i >= 1; --i) {
    if (pi[i] * (long long)q <= rub[i] * (long long)p) {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("Palindromic tree is better than splay tree\n");
  return 0;
}
