#include <bits/stdc++.h>
using namespace std;
string toString(int n) {
  ostringstream s;
  s << n;
  return s.str();
}
bool equal(double a, double b) { return fabs(a - b) < 1e-6; }
bool isPalindrome(string s) {
  for (int i = 0; i < s.length() / 2; i++) {
    if (s[i] != s[s.length() - i - 1]) {
      return false;
    }
  }
  return true;
}
int main() {
  double p, q;
  int maxi = 1200000;
  vector<int> s;
  cin >> p >> q;
  for (int i = 1; i <= maxi; i++) s.push_back(i);
  s[0] = 0;
  for (int i = 2; i <= maxi; i++) {
    if (s[i - 1] != 0) {
      for (int j = 2 * s[i - 1]; j < maxi; j += s[i - 1]) {
        s[j - 1] = 0;
      }
    }
  }
  int *palindromes = new int[maxi];
  int *primes = new int[maxi];
  for (int i = 0; i < maxi; i++) {
    primes[i] = 0;
    palindromes[i] = 0;
  }
  for (int i = 2; i < maxi; i++) {
    if (s[i - 1] != 0) {
      primes[i] = primes[i - 1] + 1;
    } else {
      primes[i] = primes[i - 1];
    }
  }
  for (int i = 1; i < maxi; i++) {
    if (isPalindrome(toString(i))) {
      palindromes[i] = palindromes[i - 1] + 1;
    } else {
      palindromes[i] = palindromes[i - 1];
    }
  }
  int m = -1;
  for (int i = 1; i < maxi; i++) {
    double p1 = palindromes[i];
    double p2 = primes[i];
    if (p2 <= p1 * p / q) {
      m = i;
    }
  }
  if (m != -1) {
    cout << m << endl;
  } else {
    cout << "Palindromic tree is better than splay tree" << endl;
  }
}
