#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 + 2e6;
int snt(int n) {
  if (n < 2) {
    return 0;
  } else if (n > 2) {
    if (n % 2 == 0) {
      return 0;
    }
    for (int i = 3; i <= sqrt((float)n); i += 2) {
      if (n % i == 0) {
        return 0;
      }
    }
  }
  return 1;
}
int dx(int n) {
  int d[100000 + 2];
  int i = 1;
  while (n) {
    d[i] = n % 10;
    n = n / 10;
    if (n) i++;
  }
  int h = i;
  for (int j = 1; j <= h / 2; j++)
    if (d[j] != d[h - j + 1]) return 0;
  return 1;
}
int main() {
  int p, q;
  cin >> p >> q;
  int n = 1;
  int nprime = 0;
  int npal = 0;
  int r;
  for (int i = 1; i <= maxn; i++) {
    if (snt(i)) nprime++;
    if (dx(i)) npal++;
    if (q * nprime <= p * npal) r = i;
  }
  cout << r;
}
