#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename T>
string to_str(T str) {
  stringstream stream;
  stream << str;
  return stream.str();
}
template <typename T>
int to_int(T num) {
  int val;
  stringstream stream;
  stream << num;
  stream >> val;
  return val;
}
vector<string> split(const string& s, char delim) {
  vector<string> elems;
  stringstream ss(s);
  string item;
  while (getline(ss, item, delim)) elems.push_back(item);
  return elems;
}
const int dr[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int MAX = (8 << 20);
bool prime[MAX];
char s[10];
bool ispal(int n) {
  int m = 0, a[10];
  for (; n > 0; n /= 10) a[m++] = n % 10;
  for (int i = 0; i < (m / 2); i++)
    if (a[i] != a[m - 1 - i]) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  memset(prime, true, sizeof(prime));
  prime[1] = false;
  for (int n = (2); n <= (MAX); n++)
    if (prime[n])
      for (int m = n + n; m < MAX; m += n) prime[m] = false;
  int p, q;
  cin >> p >> q;
  int c1 = 0, c2 = 0;
  int ans = 1;
  for (int i = 1; i <= MAX; i++) {
    if (ispal(i)) c2++;
    if (prime[i]) c1++;
    if (1ll * q * c1 <= 1ll * p * c2) ans = i;
  }
  cout << ans << endl;
  return 0;
}
