#include <bits/stdc++.h>
const int N = 10000000;
int a[10];
int pr[N + 1];
int pal[N + 1];
void gen(int k, int len) {
  if (k == (len + 1) / 2) {
    int cur = 0;
    for (int i = 0; i < len; i++) {
      cur = cur * 10 + a[i];
    }
    pal[cur] = 1;
  } else {
    for (int i = !k; i <= 9; i++) {
      a[k] = a[len - k - 1] = i;
      gen(k + 1, len);
    }
  }
}
int main() {
  int p, q;
  scanf("%d %d", &p, &q);
  for (int i = 2; i <= N; i++) {
    pr[i] = 1;
  }
  for (int i = 2; i <= N; i++) {
    if (pr[i]) {
      for (int j = i + i; j <= N; j += i) {
        pr[j] = 0;
      }
    }
  }
  for (int i = 1; i <= 7; i++) {
    gen(0, i);
  }
  for (int i = 2; i <= N; i++) {
    pr[i] += pr[i - 1];
    pal[i] += pal[i - 1];
  }
  for (int i = N; i >= 1; i--) {
    if (pr[i] * 1LL * q <= pal[i] * 1LL * p) {
      printf("%d\n", i);
      return 0;
    }
  }
}
