#include <bits/stdc++.h>
using namespace std;
int isparolil(int x) {
  char ss[10];
  int cnt = 1;
  while (x) {
    ss[cnt++] = x % 10;
    x /= 10;
  }
  for (int i = 1; i <= (cnt - 1) / 2; i++) {
    if (ss[i] != ss[cnt - i]) return 0;
  }
  return 1;
}
int prime[2000000];
int ans[2000000];
int ans2[2000000];
double ans3[2000000];
int main() {
  double p, q;
  memset(prime, 0, sizeof(prime));
  int cnt = 0;
  int cnt2 = 1;
  ans2[1] = 1;
  for (int i = 2; i < 2000000; i++) {
    if (!prime[i]) {
      cnt++;
      for (int j = i << 1; j < 2000000; j += i) prime[j] = 1;
    }
    if (isparolil(i)) {
      cnt2++;
    }
    ans[i] = cnt;
    ans2[i] = cnt2;
    ans3[i] = 1.0 * cnt / cnt2;
  }
  cin >> p >> q;
  double x = 1.0 * p / q;
  int pos;
  for (int i = 1; i < 2000000; i++) {
    if (x >= ans3[i]) {
      pos = i;
    }
  }
  cout << pos << endl;
  return 0;
}
