#include <bits/stdc++.h>
const int mx = 1e7 + 10;
;
using namespace std;
long long cpr[mx], cpal[mx];
int x, y;
bool p[mx];
int main() {
  memset(p, true, sizeof p);
  for (int i = 2; i * i < mx; i++) {
    if (p[i]) {
      for (int j = i + i; j < mx; j += i) p[j] = false;
    }
  }
  cpr[0] = cpr[1] = 0;
  for (int i = 2; i < mx; i++) {
    cpr[i] = cpr[i - 1] + (int)(p[i] == true);
  }
  cpal[1] = 1;
  for (int i = 2; i < mx; i++) {
    int r = i, m = 0;
    while (r) {
      m = m * 10 + r % 10;
      r /= 10;
    }
    cpal[i] = cpal[i - 1];
    if (i == m) ++cpal[i];
  }
  scanf("%d%d", &x, &y);
  int l = 0, r = mx - 1;
  int ans = -1, m;
  for (int i = 1; i < mx; i++) {
    if (cpr[i] * 1LL * y <= cpal[i] * 1LL * x) ans = i;
  }
  if (ans == -1)
    puts("alindromic tree is better than splay tree");
  else
    printf("%d\n", ans);
  return 0;
}
