#include <bits/stdc++.h>
using namespace std;
int i, m, p, q, t1, t2;
inline bool check1(int x) {
  if (x == 1) return false;
  for (int i = 2; i * i <= x; i++)
    if (!(x % i)) return false;
  return true;
}
inline bool check2(int x) {
  char c[10];
  c[0] = 0;
  for (; x; x = x / 10) c[0]++, c[c[0]] = x % 10;
  for (int i = 1; i <= c[0]; i++)
    if (c[i] != c[c[0] + 1 - i]) return false;
  return true;
}
int main() {
  scanf("%d%d", &p, &q);
  for (i = 1; i <= 1200000; i++) {
    if (check1(i)) t1++;
    if (check2(i)) t2++;
    if (1LL * q * t1 <= 1LL * p * t2) m = max(m, i);
  }
  if (m)
    printf("%d\n", m);
  else
    printf("Palindromic tree is better than splay tree\n");
  return 0;
}
