#include <bits/stdc++.h>
using namespace std;
const int maxn = 1211000;
int isPrime[maxn];
int sum_prime[maxn] = {0};
int sum_pali[maxn] = {0};
bool check(int x) {
  char s[40];
  sprintf(s, "%d", x);
  int len = strlen(s);
  for (int i = 0; i < len / 2; i++) {
    if (s[i] != s[len - i - 1]) return false;
  }
  return true;
}
int main() {
  memset(isPrime, -1, sizeof isPrime);
  isPrime[1] = false;
  for (int i = 2; i < maxn; i++) {
    if (isPrime[i])
      for (long long j = (long long)i * i; j < (long long)maxn; j += i) {
        isPrime[j] = false;
      }
  }
  for (int i = 1; i < maxn; i++) {
    sum_pali[i] = sum_pali[i - 1] + (check(i) ? 1 : 0);
  }
  for (int i = 2; i < maxn; i++) {
    sum_prime[i] = sum_prime[i - 1] + (isPrime[i] ? 1 : 0);
  }
  int p, q;
  cin >> p >> q;
  for (int i = maxn - 10; i >= 1; i--) {
    if (q * sum_prime[i] <= p * sum_pali[i]) {
      cout << i;
      break;
    }
  }
  return 0;
}
