#include <bits/stdc++.h>
int main() {
  long long palite, primeite;
  std::cin >> palite >> primeite;
  long long primes = 0, palindromes = 0, max;
  static bool prime[12000001];
  for (long long i = 0; i <= 12000000; i++) {
    prime[i] = true;
  }
  prime[1] = false;
  std::string str = "0";
  for (long long i = 1; i <= 12000000; i++) {
    if (prime[i]) {
      primes += primeite;
      for (long long j = i * i; j <= 12000000; j += i) {
        prime[j] = false;
      }
    }
    long long pos;
    for (pos = str.length() - 1; pos >= 0; pos--) {
      if (str[pos] == '9') {
        str[pos] = '0';
      } else {
        str[pos]++;
        break;
      }
    }
    if (pos == -1) {
      str.insert(str.begin(), '1');
    }
    palindromes += palite;
    for (long long j = 0, back = str.length() - 1; back > j; j++, back--) {
      if (str[j] != str[back]) {
        palindromes -= palite;
        break;
      }
    }
    if (primes <= palindromes) {
      max = i;
    }
  }
  if (max == 12000000) {
    std::cout << "Palindromic tree is better than splay tree";
  } else {
    std::cout << max;
  }
  return 0;
}
