#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1588888;
vector<int> primes(MAXN);
vector<int> palindromes(MAXN);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int p, q;
  cin >> p >> q;
  for (int i = 0; i < MAXN; ++i) primes[i] = 1;
  primes[0] = 0;
  primes[1] = 0;
  for (int i = 2; i <= sqrt(MAXN); ++i) {
    if (primes[i] == 1) {
      for (int j = i + i; j < MAXN; j += i) {
        primes[j] = 0;
      }
    }
  }
  for (int i = 0; i < MAXN; ++i) palindromes[i] = 0;
  for (int i = 1; i < MAXN; ++i) {
    char buf[30];
    sprintf(buf, "%d", i);
    bool p = true;
    int len = strlen(buf);
    for (int j = 0; j < len / 2; ++j) {
      if (buf[j] != buf[len - j - 1]) {
        p = false;
        break;
      }
    }
    if (p) palindromes[i] = 1;
  }
  for (int i = 1; i < MAXN; ++i) {
    primes[i] += primes[i - 1];
    palindromes[i] += palindromes[i - 1];
  }
  int i = 1;
  int ma = 0;
  while (i < MAXN) {
    if ((primes[i]) * q <= p * (palindromes[i])) {
      ma = i;
    }
    i++;
  }
  cout << ma << "\n";
  return 0;
}
