#include <bits/stdc++.h>
using namespace std;
int pr[1300000] = {1, 1};
int rev(int n) {
  int r = 0;
  while (n) r = 10 * r + n % 10, n /= 10;
  return r;
}
int main() {
  int p, q, pi = 0, rub = 0, ans;
  cin >> p >> q;
  for (int i = 1; i < 1300000; i++) {
    if (!pr[i]) {
      pi++;
      for (int j = i; j < 1300000; j += i) pr[j] = 1;
    }
    if (rev(i) == i) rub++;
    if (q * pi <= p * rub) ans = i;
  }
  cout << ans;
}
