#include <bits/stdc++.h>
using namespace std;
const int N = 1179859;
int p, q, s1, s2;
int maxnum = 1;
bool prime[N];
bool check(int k) {
  int s1 = k, s2 = 0;
  for (; s1; s1 /= 10) s2 = s2 * 10 + s1 % 10;
  return s2 == k;
}
int main() {
  scanf("%d%d", &p, &q);
  s2 = 1;
  maxnum = 1;
  for (int i = 2; i < N; ++i) {
    if (!prime[i]) {
      for (int j = i + i; j <= N; j += i) prime[j] = true;
      s1++;
    }
    if (check(i)) s2++;
    if (q * s1 <= p * s2) maxnum = i;
  }
  printf("%d\n", maxnum);
}
