#include <bits/stdc++.h>
using namespace std;
long long int modpow(long long int a, long long int n, long long int temp) {
  long long int res = 1, y = a;
  while (n > 0) {
    if (n & 1) res = (res * y) % temp;
    y = (y * y) % temp;
    n /= 2;
  }
  return res % temp;
}
int isprime[5000006], prime[5000006], palin[5000006];
vector<pair<double, int> > arr;
void seive() {
  long long int i = 2, j, cnt = 0;
  for (; i <= 5000006; i++) {
    if (isprime[i] == 0) {
      j = i * i;
      for (; j <= 5000006; j += i) isprime[j] = 1;
    }
  }
  prime[0] = 0;
  prime[1] = 0;
  for (i = 2; i < 5000006; ++i) {
    if (isprime[i] == 0) cnt++;
    prime[i] = cnt;
  }
}
int checkpalin(int n) {
  int n1 = n, n2 = 0;
  while (n != 0) {
    n2 = n2 * 10 + n % 10;
    n /= 10;
  }
  if (n1 == n2) return 1;
  return 0;
}
int findvalue(double p, double q) {
  double calc = p / (q * 1.0), m1, m2, v1, v2;
  int low = 0, high = arr.size(), mid, ans;
  while (low <= high) {
    if (prime[low] * q <= palin[low] * p) ans = low;
    low++;
  }
  return ans;
}
int main() {
  int i, calc, ans = 0;
  double p, q, cit;
  seive();
  palin[0] = 0;
  for (i = 1; i < 5000006; ++i) {
    calc = checkpalin(i);
    if (calc) ans++;
    palin[i] = ans;
  }
  for (i = 1; i < 5000006; ++i) {
    cit = prime[i] / (palin[i] * 1.0);
    if (i == 251116 || i == 251262)
      cerr << "i"
           << ": " << i << " | "
           << "prime[i]"
           << ": " << prime[i] << " | "
           << "palin[i]"
           << ": " << palin[i] << " | "
           << "cit"
           << ": " << cit << endl;
    ;
    arr.push_back(make_pair(cit, i));
  }
  sort(arr.begin(), arr.end());
  scanf("%lf", &p);
  scanf("%lf", &q);
  ans = findvalue(p, q);
  cerr << "prime[ans]"
       << ": " << prime[ans] << " | "
       << "palin[ans]"
       << ": " << palin[ans] << endl;
  ;
  cerr << "prime[ans + 1]"
       << ": " << prime[ans + 1] << " | "
       << "palin[ans + 1]"
       << ": " << palin[ans + 1] << endl;
  ;
  printf("%d\n", ans);
  return 0;
}
