#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INF_LL = 4e18;
const double pi = acos(-1.0);
template <class T>
T& smin(T& a, const T& b) {
  if (a > b) a = b;
  return a;
}
template <class T>
T& smax(T& a, const T& b) {
  if (a < b) a = b;
  return a;
}
template <class T>
T sqr(const T& a) {
  return a * a;
}
template <typename Iterator>
void print(const char* fmt, Iterator begin, Iterator end,
           const char* separator = " ", const char* closing = "\n") {
  for (Iterator it = begin; it != end;
       printf(fmt, *it), printf("%s", ++it == end ? closing : separator))
    ;
}
int p, q;
const int N = 2e6;
bitset<N / 2> y;
void gen_primes() {
  y.set();
  for (int i(0), _b((N - 1) / 2); i < _b; ++i)
    if (y[i]) {
      int v = 2 * i + 3;
      for (int u = v, m = N / v; u <= m; u += 2) y.reset((v * u - 3) / 2);
    }
}
bool is_prime(int v) {
  if (v == 1) return false;
  if (v == 2) return true;
  if (v % 2 == 0) return false;
  return y[(v - 3) / 2];
}
vector<int> d;
bool is_pal(int v) {
  d.clear();
  while (v) d.push_back(v % 10), v /= 10;
  for (int i = 0, j = int((d).size()) - 1; i < j; ++i, --j)
    if (d[i] != d[j]) return false;
  return true;
}
int main() {
  cin.tie(NULL);
  scanf("%d%d", &p, &q);
  gen_primes();
  int pr = 0, pal = 0;
  int ans = 0;
  for (int n(1), _b(N); n < _b; ++n) {
    if (is_prime(n)) ++pr;
    if (is_pal(n)) ++pal;
    if (pr * q <= p * pal) ans = n;
  }
  printf("%d\n", ans);
  return 0;
}
