#include <bits/stdc++.h>
using namespace std;
void output(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x == 0) {
    putchar('0');
    return;
  }
  int a[20], num = 0;
  while (x) a[++num] = x % 10, x /= 10;
  while (num > 0) putchar('0' + a[num--]);
}
inline long long myInt() {
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  int flag = 1;
  if (c == '-') flag = -1, c = getchar();
  long long x = 0;
  while (isdigit(c)) {
    x = (x * 10) + (c - '0');
    c = getchar();
  }
  if (-1 == flag) return -x;
  return x;
}
const int INF = 2000000005;
const int N = 2000005;
int prime[N], tag[N], pNum;
int f[N];
int g[N];
int ok(int x) {
  if (x < 10) return 1;
  int a[15], aNum = 0;
  while (x) a[aNum++] = x % 10, x /= 10;
  int L = 0, R = aNum - 1;
  while (L < R) {
    if (a[L] != a[R]) return 0;
    L++;
    R--;
  }
  return 1;
}
void init() {
  for (int i = 2; i < N; i++)
    if (!tag[i]) {
      for (int j = i + i; j < N; j += i) tag[j] = 1;
    }
  for (int i = 2; i < N; i++) {
    f[i] = f[i - 1];
    if (!tag[i]) f[i]++;
  }
  g[0] = 0;
  for (int i = 1; i < N; i++) g[i] = g[i - 1] + ok(i);
}
int p, q;
int main() {
  init();
  p = myInt();
  q = myInt();
  for (int i = N - 1; i >= 1; i--) {
    if ((long long)f[i] * q <= p * g[i]) {
      printf("%d\n", i);
      return 0;
    }
  }
  puts("Palindromic tree is better than splay tree");
}
