#include <bits/stdc++.h>
const int N = 7000000;
int primes[N], pal[N];
bool sieve[N];
int main() {
  int p, q, ans = 0;
  scanf("%d%d", &p, &q);
  for (int i = 2; i < N; ++i) {
    sieve[i] = true;
  }
  for (int i = 2; i * i <= N; ++i) {
    if (sieve[i]) {
      for (int j = i * i; j <= N; j += i) {
        sieve[j] = false;
      }
    }
  }
  for (int i = 2; i < N; ++i) {
    if (sieve[i]) {
      ++primes[i];
    }
    primes[i] += primes[i - 1];
  }
  for (int i = 1; i < N; ++i) {
    pal[i] += pal[i - 1];
    int rev = 0, j = i;
    while (j > 0) {
      rev *= 10;
      rev += j % 10;
      j /= 10;
    }
    if (rev == i) {
      ++pal[i];
    }
  }
  for (int i = 0; i < N; ++i) {
    if (q * 1ll * primes[i] <= p * 1ll * pal[i]) {
      ans = i;
    }
  }
  printf("%d\n", ans);
  return 0;
}
