#include <bits/stdc++.h>
using namespace std;
inline void FAST_IO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
template <class F, class S>
ostream& operator<<(ostream& os, pair<F, S>& p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  os << "(";
  if (v.size()) os << v[0];
  for (int i = 1; i < v.size(); ++i) os << "," << v[i];
  os << ")";
  return os;
}
int main() {
  int p, q;
  cin >> p >> q;
  int n = 1200000;
  vector<bool> primes(n + 1, true);
  primes[0] = primes[1] = false;
  for (int i = 2; i <= n; ++i) {
    if (!primes[i]) continue;
    for (int j = i + i; j <= n; j += i) {
      primes[j] = false;
    }
  }
  int lo = 0;
  int hi = 0;
  int resp = ~(1 << 31);
  char str[10]{0};
  for (int i = 1; i <= n; ++i) {
    sprintf(str, "%d", i);
    int sz = strlen(str);
    bool palindrome = true;
    for (int j = 0; j < sz / 2; ++j) {
      palindrome &= (str[j] == str[sz - j - 1]);
    }
    lo += primes[i];
    hi += palindrome;
    if (lo * q <= hi * p) resp = i;
  }
  if (resp == ~(1 << 31))
    cout << "Palindromic tree is better than splay tree" << endl;
  else
    cout << resp << endl;
  return 0;
}
