#include <bits/stdc++.h>
using namespace std;
int x, y, m, n, k, t, p, q;
int ans, ans1;
char ch[100];
int su[1000000 + 10];
bool le[2000000 + 10];
int hui[1000000 + 10];
void shai() {
  memset(le, 0, sizeof(le));
  le[1] = 1;
  for (int i = 2; i <= sqrt(1500000); i++) {
    if (le[i] == 0) {
      for (int j = 2; j * i <= 1500000; j++) {
        le[i * j] = 1;
      }
    }
  }
}
bool judge(int k) {
  if (k < 10) return 1;
  sprintf(ch, "%d", k);
  int t = strlen(ch);
  int t1 = t / 2;
  for (int i = 0; i <= t1 - 1; ++i)
    if (ch[i] != ch[t - i - 1]) return false;
  return true;
}
int main() {
  shai();
  scanf("%d%d", &p, &q);
  for (int i = 1; i <= 1500000; ++i) {
    if (!le[i]) x = x + 1;
    if (judge(i)) y = y + 1;
    if ((long long)q * x <= (long long)p * y) ans = i;
  }
  printf("%d", ans);
  return 0;
}
