#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool read(T &x) {
  int c = getchar();
  int sgn = 1;
  while (~c && c<'0' | c> '9') {
    if (c == '-') sgn = -1;
    c = getchar();
  }
  for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  x *= sgn;
  return ~c;
}
struct debugger {
  template <typename T>
  debugger &operator,(const T &v) {
    cerr << v << "    ";
    return *this;
  }
} dbg;
template <class T>
void __stl_print__(T &x) {
  cerr << "[";
  for (__typeof((x).end()) i = (x).begin(); i != (x).end(); ++i)
    cerr << (i != x.begin() ? ", " : "") << *i;
  cerr << "]" << endl;
}
template <class T, class U>
inline T max(T &a, U &b) {
  return a > b ? a : b;
}
template <class T, class U>
inline T min(T &a, U &b) {
  return a < b ? a : b;
}
template <class T, class U>
inline T swap(T &a, U &b) {
  T tmp = a;
  a = b;
  b = tmp;
}
const long long INF = (1ll) << 50;
const int mx = 1e5 + 7;
const int mod = 1000000007;
const double pi = 2 * acos(0.0);
int EQ(double d) {
  if (fabs(d) < 1e-7) return 0;
  return d > 1e-7 ? 1 : -1;
}
unsigned int prime[5000000 / 64], pr[5000000], prlen;
void sieve() {
  unsigned int i, j, sqrtN, i2;
  memset(prime, -1, sizeof(prime));
  sqrtN = (long long)sqrt((double)5000000) + 1;
  for (i = 3; i < sqrtN; i += 2)
    if ((prime[i >> 6] & (1 << ((i >> 1) & 31))))
      for (j = i * i, i2 = i << 1; j < 5000000; j += i2)
        (prime[j >> 6] &= ~(1 << ((j >> 1) & 31)));
  pr[prlen++] = 2;
  for (i = 3; i < 5000000; i += 2)
    if ((prime[i >> 6] & (1 << ((i >> 1) & 31)))) pr[prlen++] = i;
}
char a[100];
int main() {
  sieve();
  int p = ({
    int a;
    read(a);
    a;
  }),
      q = ({
        int a;
        read(a);
        a;
      });
  long long cnt = 0;
  int ans = 0;
  for (__typeof(5000000 - 2) i = (1); i <= (5000000 - 2); ++i) {
    int len = 0, tmp = i;
    while (tmp) {
      a[len++] = tmp % 10;
      tmp /= 10;
    }
    bool f = 1;
    for (__typeof((len / 2) - 1) j = (0); j <= ((len / 2) - 1); ++j) {
      f &= (a[j] == a[len - j - 1]);
    }
    cnt += f;
    long long l = lower_bound(pr, pr + prlen, i) - pr;
    while (l >= 0 && pr[l] > i) l--;
    l++;
    if (p * cnt >= q * l) ans = i;
  }
  cout << ans << endl;
}
