#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int upperBound = 2 * 1000000;
int isComposite[2000001] = {0};
void runEratosthenesSieve() {
  int upperBoundSquareRoot = (int)sqrt((double)upperBound);
  memset(isComposite, 0, sizeof(bool) * (upperBound + 1));
  for (int m = 2; m <= upperBoundSquareRoot; m++) {
    if (isComposite[m] == 0) {
      for (int k = m * m; k <= upperBound; k += m) isComposite[k] = 1;
    }
  }
  for (int m = 2; m <= upperBound; m++) {
    if (isComposite[m] == 0)
      isComposite[m] = isComposite[m - 1] + 1;
    else
      isComposite[m] = isComposite[m - 1];
  }
}
int a[2000001] = {0};
void palindrom() {
  for (int i = 1; i <= 2000000; i++) {
    string s = "";
    int j = i;
    while (j != 0) {
      s += j % 10;
      j /= 10;
    }
    string w = s;
    reverse(s.begin(), s.end());
    if (w == s) {
      a[i] = a[i - 1] + 1;
    } else
      a[i] = a[i - 1];
  }
}
int main(int argc, char** argv) {
  int p, q;
  cin >> p >> q;
  palindrom();
  runEratosthenesSieve();
  double b = 1. * p / q;
  int pos;
  for (int i = 1; i <= 2000000; i++) {
    if (p * (a[i]) >= q * isComposite[i]) {
      pos = i;
    }
  }
  cout << pos << endl;
  return 0;
}
