#include <bits/stdc++.h>
char s[12];
inline bool C(int x) {
  sprintf(s, "%d", x);
  int n = strlen(s);
  for (int i = (0), __ = (n / 2); i < __; ++i) {
    if (s[i] != s[n - i - 1]) return 0;
  }
  return 1;
}
int a[2000033];
inline bool check(int x) {
  if (x == 1) return 0;
  for (int i = (2), __ = (sqrt(x)); i <= __; ++i)
    if (x % i == 0) return 0;
  return 1;
}
int b[2000033];
int n;
int p, q;
std::set<std::pair<double, int> > S;
int main() {
  b[0] = 0;
  b[1] = 0;
  a[0] = 0;
  a[1] = 1;
  scanf("%d%d", &p, &q);
  int ll = 1, rr = n, mid;
  double ss = p * 1.0 / q;
  n = 1190000;
  for (int i = (1), __ = (n); i <= __; ++i) {
    a[i] = a[i - 1];
    if (C(i)) ++a[i];
    b[i] = b[i - 1];
    if (check(i)) ++b[i];
  }
  for (int i = (n), __ = (1); i >= __; --i)
    if (double(b[i]) * 1.0 / double(a[i]) - ss <= 1e-6) {
      printf("%d\n", i);
      return 0;
    }
  while (double(b[ll] * 1.0 / a[ll]) <= ss) {
    ++ll;
  }
  printf("%lf\n", ss);
  printf("%lf\n", double(b[ll] * 1.0 / a[ll]) - ss);
  printf("%d\n", ll - 1);
  printf("%d\n", ll);
  return 0;
}
