#include <bits/stdc++.h>
const int maxn = 1.5 * 10e6;
using namespace std;
bool pri_f[maxn];
int pri[maxn];
int pal[maxn];
void pre_pri() {
  memset(pri_f, false, sizeof(pri_f));
  memset(pri, 0, sizeof(pri));
  pri[1] = 0;
  for (int i = 2; i < maxn; i++) {
    pri[i] += pri[i - 1];
    if (!pri_f[i]) {
      pri[i]++;
      for (int j = i; j < maxn; j += i) {
        pri_f[j] = true;
      }
    }
  }
}
void pre_pal() {
  pal[0] = 0;
  for (int i = 1; i < maxn; i++) {
    pal[i] = pal[i - 1];
    int tmp = i;
    int tmp_2 = 0;
    while (tmp) {
      tmp_2 *= 10;
      tmp_2 += tmp % 10;
      tmp /= 10;
    }
    if (tmp_2 == i) pal[i]++;
  }
}
int main() {
  double p, q;
  double A;
  int max_ans;
  pre_pal();
  pre_pri();
  scanf("%lf %lf", &p, &q);
  A = p / q;
  for (int i = 1; i < maxn; i++) {
    if (pri[i] <= A * pal[i]) {
      max_ans = i;
    }
  }
  cout << max_ans << endl;
}
