#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10000000;
bool isPrime[MAXN], isPolyndrome[MAXN];
void eratosphen() {
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i * i < MAXN; i++) {
    if (isPrime[i]) {
      for (int j = i * i; j < MAXN; j += i) {
        isPrime[j] = false;
      }
    }
  }
}
void polyndrome_generator() {
  for (int i = 0; i < 10; i++) {
    isPolyndrome[i] = true;
  }
  for (int i = 1; i < 1000; i++) {
    string s = to_string((long long)i), revs = s;
    reverse(revs.begin(), revs.end());
    isPolyndrome[stoi(s + revs)] = true;
    for (int j = 0; j < 10; j++) {
      isPolyndrome[stoi(s + to_string((long long)j) + revs)] = true;
    }
  }
}
int main() {
  fill(isPrime, isPrime + MAXN, true);
  fill(isPolyndrome, isPolyndrome + MAXN, false);
  long long p, q, primeCount = 0, polCount = 0, maxIndex = 1;
  cin >> p >> q;
  eratosphen();
  polyndrome_generator();
  for (int i = 1; i < MAXN; i++) {
    if (isPolyndrome[i]) polCount++;
    if (isPrime[i]) primeCount++;
    if (q * primeCount <= p * polCount) maxIndex = i;
  }
  cout << maxIndex << endl;
}
