#include <bits/stdc++.h>
template <typename T>
bool Chkmax(T &x, T y) {
  return x < y ? x = y, true : false;
}
template <typename T>
bool Chkmin(T &x, T y) {
  return y < x ? x = y, true : false;
}
const int MAXN = 5e6;
int totpri;
int rub[MAXN], pi[MAXN];
int pri[MAXN];
bool flag[MAXN];
void Work(int x) {
  int x0 = x, y = 0, base = 1;
  while (x0) {
    y = y * 10 + x0 % 10;
    x0 /= 10;
    base *= 10;
  }
  std::swap(x, y);
  if (y * base + x >= MAXN) return;
  rub[y * base + x] = 1;
  for (int i = 0, _ = 9; i <= _; i++) {
    int z = y * base * 10 + i * base + x;
    if (z >= MAXN) return;
    rub[z] = 1;
  }
}
void Init(int N = MAXN - 1) {
  for (int i = 2, _ = N; i <= _; i++) {
    if (!flag[i]) {
      pri[++totpri] = i;
      pi[i] = 1;
    }
    for (int j = 1; j <= totpri && i * pri[j] <= N; j++) {
      flag[i * pri[j]] = true;
      if (i % pri[j] == 0) break;
    }
  }
  for (int i = 0, _ = 9999; i <= _; i++) Work(i);
  rub[0] = 0;
  for (int i = 2, _ = N; i <= _; i++) {
    rub[i] += rub[i - 1], pi[i] += pi[i - 1];
  }
}
int main() {
  if (fopen("568A.in", "r") != NULL) {
    freopen("568A.in", "r", stdin);
    freopen("568A.out", "w", stdout);
  }
  int p, q;
  Init();
  scanf("%d%d", &p, &q);
  for (int i = MAXN - 1, _ = 1; i >= _; i--)
    if ((long long)pi[i] * q <= (long long)rub[i] * p) {
      printf("%d\n", i);
      fprintf(stderr, "rub: %d, pi: %d\n", rub[i], pi[i]);
      return 0;
    }
}
