#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, P, q;
int f[5000010], p[5000010], ge[5000010], s[5000010];
inline int pan(int x) {
  int s = 0, y = x;
  for (; x; x /= 10) s = s * 10 + x % 10;
  return s == y;
}
int main() {
  for (i = 2; i <= 5000010 - 1; i++) {
    if (!f[i]) f[i] = p[++*p] = i;
    for (j = 1; j <= *p && p[j] <= f[i] && i * p[j] < 5000010; j++)
      f[i * p[j]] = p[j];
  }
  for (i = 1; i <= 5000010 - 1; i++) {
    ge[i] = ge[i - 1] + pan(i);
    s[i] = s[i - 1] + (f[i] == i);
  }
  scanf("%d%d", &P, &q);
  int an = 0;
  for (i = 1; i <= 5000010 - 1; i++)
    if (1ll * s[i] * q <= 1ll * P * ge[i]) an = i;
  printf("%d\n", an);
  return 0;
}
