#include <bits/stdc++.h>
using namespace std;
const int MAX_NUMBER = 10 * 1000 * 1000;
const int ARRAYS_SIZE = MAX_NUMBER + 1;
bool isPrime[ARRAYS_SIZE];
bool isPalyndrome[ARRAYS_SIZE];
int main(void) {
  for (int i = 0; i < MAX_NUMBER; ++i) {
    isPrime[i] = isPalyndrome[i] = true;
  }
  isPalyndrome[0] = false;
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i < MAX_NUMBER; ++i) {
    if (isPrime[i] && (long long)(i)*i <= MAX_NUMBER) {
      for (int j = i * i; j < MAX_NUMBER; j += i) {
        isPrime[j] = false;
      }
    }
  }
  int cur10 = 10;
  int next10 = 100;
  for (int i = 10; i < MAX_NUMBER; ++i) {
    if (i >= next10) {
      cur10 = next10;
      next10 *= 10;
    }
    int cur = i;
    int s10 = cur10;
    while (cur > 0) {
      isPalyndrome[i] &= (cur % 10) == (cur / s10);
      cur = (cur - cur / s10 * s10) / 10;
      s10 /= 100;
    }
  }
  long long p, q;
  cin >> p >> q;
  int countPrime = 0;
  int countPalyndrome = 0;
  int best = 0;
  for (int i = 0; i < MAX_NUMBER; ++i) {
    countPrime += isPrime[i];
    countPalyndrome += isPalyndrome[i];
    if (countPrime * q <= p * countPalyndrome) {
      best = i;
    }
  }
  cout << best << endl;
  return 0;
}
