#include <bits/stdc++.h>
using namespace std;
bool p[4000010], h[4000010];
long long a, b, pi[4000010], rub[4000010];
int main() {
  scanf("%I64d%I64d", &a, &b);
  for (int i = 2; i <= 4000000; i++) p[i] = 1;
  memset(h, 0, sizeof(h));
  p[1] = 0;
  for (int i = 2; i <= 2000; i++)
    if (p[i])
      for (int j = i * i; j <= 4000000; j += i) p[j] = 0;
  for (int i = 1; i <= 3999; i++) {
    int t = i, k = 0, c[15], n = 0;
    while (t > 0) {
      c[++k] = t % 10;
      t /= 10;
    }
    for (int j = k; j >= 1; j--) n = n * 10 + c[j];
    for (int j = 1; j <= k; j++) n = n * 10 + c[j];
    if (n <= 4000000) h[n] = 1;
    n = 0;
    for (int j = k; j >= 2; j--) n = n * 10 + c[j];
    for (int j = 1; j <= k; j++) n = n * 10 + c[j];
    if (n <= 4000000) h[n] = 1;
  }
  pi[0] = 0;
  rub[0] = 0;
  for (int i = 1; i <= 4000000; i++) {
    if (p[i])
      pi[i] = pi[i - 1] + 1;
    else
      pi[i] = pi[i - 1];
    if (h[i])
      rub[i] = rub[i - 1] + 1;
    else
      rub[i] = rub[i - 1];
  }
  for (int i = 4000000; i >= 1; i--)
    if (pi[i] * b <= rub[i] * a) {
      printf("%d", i);
      return 0;
    }
}
