#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v);
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
  return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v) {
  cout << "[";
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << ", ";
    cout << v[i];
  }
  return cout << "]";
}
template <typename A, typename B>
istream &operator>>(istream &cin, pair<A, B> &p) {
  cin >> p.first;
  return cin >> p.second;
}
const long long MAXN = 2e6 + 7;
std::vector<long long> p_n;
long long a[MAXN + 1] = {0}, b[MAXN] = {0};
long long createPalindrome(long long input, long long b1, bool isOdd) {
  long long n = input, palin = input;
  if (isOdd) n /= b1;
  while (n > 0) {
    palin = palin * b1 + (n % b1);
    n /= b1;
  }
  return palin;
}
void generatePalindromes(long long n) {
  long long number;
  for (long long j = 0; j < 2; j++) {
    long long i = 1;
    while ((number = createPalindrome(i, 10, j % 2)) < n) {
      p_n.push_back(number);
      a[number]++;
      i++;
    }
  }
  for (long long i = 1; i < n; i++) a[i] += a[i - 1];
}
template <long long SZ>
struct Sieve {
  bitset<SZ> pri;
  vector<long long> pr;
  Sieve() {
    pri.set();
    pri[0] = pri[1] = 0;
    for (int i = 4; i < SZ; i += 2) {
      pri[i] = 0;
    }
    for (int i = 3; i * i < SZ; i += 2) {
      if (pri[i]) {
        for (int j = i * i; j < SZ; j += 2 * i) {
          pri[j] = 0;
        }
      }
    }
    for (int i = 2; i < SZ; i++) {
      b[i] += b[i - 1];
      if (pri[i]) {
        pr.push_back(i);
        b[i]++;
      }
    }
  }
};
void check() {
  long long p, q;
  cin >> p >> q;
  long long l = 0, r = MAXN - 1, m, ans = 0;
  auto get = [&](long long x) -> bool { return (b[x] * q) <= (p * a[x]); };
  long long ans2 = 0;
  for (long long i = 0; i < MAXN; i++) {
    if (get(i)) ans2 = i;
  }
  ans = ans2;
  if (ans == 0) {
    cout << "Palindromic tree is better than splay tree";
    return;
  }
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  Sieve<MAXN> Si;
  generatePalindromes(MAXN);
  for (int i = 1; i <= t; i++) {
    check();
  }
  return 0;
}
