#include <bits/stdc++.h>
using namespace std;
int ispalindrome(int x) {
  vector<int> d;
  while (x) {
    d.push_back(x % 10);
    x /= 10;
  }
  int l1 = 0, l2 = d.size() - 1;
  int fg = 1;
  while (l1 < l2) {
    if (d[l1] != d[l2]) {
      fg = 0;
      break;
    }
    l1++;
    l2--;
  }
  return fg;
}
int rub[12 * 100010];
void getpalindromes() {
  for (int i = 1; i <= 1200000; i++) rub[i] = rub[i - 1] + ispalindrome(i);
}
vector<int> pi(15 * 100010, 1);
void sieve() {
  pi[0] = pi[1] = 0;
  for (int i = 2; i * i <= 1200000; i++) {
    if (pi[i]) {
      for (int j = i + i; j <= 1200000; j += i) pi[j] = 0;
    }
  }
  for (int i = 3; i <= 1200000; i++) pi[i] += pi[i - 1];
}
int main() {
  sieve();
  getpalindromes();
  int p, q, ans = -1;
  cin >> p >> q;
  for (int i = 1; i <= 1200000; i++) {
    if ((long long)q * pi[i] <= (long long)p * rub[i]) ans = i;
  }
  cout << ans << "\n";
  return 0;
}
