#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
template <class T>
void parr(T *a, T *b) {
  for (T *i = a; i < b; ++i) cout << *i << ' ';
}
template <typename T>
inline bool chkmin(T &a, T b) {
  return a > b ? a = b, true : false;
}
template <typename T>
inline bool chkmax(T &a, T b) {
  return a < b ? a = b, true : false;
}
const int maxN = 1e7 + 5;
int A, B;
void get_prime(int N) {
  static bool flag[maxN];
  static int prime[maxN];
  static int stk[10], tp;
  int totprime = 0, cnt = 1, ans = -oo;
  if ((long long)totprime * B <= (long long)cnt * A) ans = 1;
  for (int i = (2); i <= (N); ++i) {
    if (flag[i] == false) {
      prime[++totprime] = i;
    }
    tp = 0;
    int tmp = i;
    while (tmp) stk[++tp] = tmp % 10, tmp = tmp / 10;
    bool Flag = true;
    for (int j = (1); j <= (tp / 2); ++j)
      if (stk[j] != stk[tp - j + 1]) {
        Flag = false;
        break;
      }
    cnt += Flag;
    if ((long long)totprime * B <= (long long)A * cnt) ans = i;
    for (int j = 1; j <= totprime && prime[j] * i <= N; ++j) {
      flag[prime[j] * i] = true;
      if (i % prime[j] == 0) {
        break;
      }
    }
  }
  if (ans != -oo)
    printf("%d\n", ans);
  else
    printf("Palindromic tree is better than splay tree\n");
}
int main() {
  scanf("%d%d", &A, &B);
  get_prime(5e6);
  return 0;
}
