#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
inline T LCM(T a, T b) {
  if (a < 0) return LCM(-a, b);
  if (b < 0) return LCM(a, -b);
  return a * (b / gcd(a, b));
}
const int MAXN = 1e7 + 32;
long long p[MAXN];
bool prime[MAXN];
long long pal[MAXN];
int main() {
  for (int i = 0; i < MAXN; i++) prime[i] = false;
  memset(p, 0, sizeof(p));
  memset(pal, 0, sizeof(pal));
  for (int i = 2; i < MAXN; i++) {
    p[i] = p[i - 1];
    if (!prime[i]) {
      p[i]++;
      for (int j = i; j <= MAXN; j = j + i) prime[j] = true;
    }
  }
  pal[0] = 0;
  for (int i = 1; i < MAXN; i++) {
    int temp = 0;
    int c = i;
    while (c > 0) {
      temp = temp * 10 + c % 10;
      c /= 10;
    }
    pal[i] = pal[i - 1];
    if (i == temp) pal[i]++;
  }
  int i = 0;
  long long p1, q1;
  cin >> p1 >> q1;
  int ans = -1;
  for (int j = 0; j < MAXN; j++) {
    if (p1 * pal[j] >= q1 * p[j]) {
      ans = j;
    }
  }
  if (ans == MAXN)
    printf("Palindromic tree is better than splay tree");
  else
    cout << ans;
  return 0;
}
