#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 50;
const int inf = 0x1f1f1f1f;
const int mod = 2333;
long long p, q, cnt1;
vector<int> a;
long long prime[maxn];
bool sf[maxn];
int sum[maxn], sum1[maxn];
void sushu() {
  long long num = 0;
  memset(sf, true, sizeof(sf));
  sf[1] = false;
  sf[0] = false;
  for (int i = 2; i <= maxn; i++) {
    if (sf[i]) prime[++num] = i;
    for (int j = 1; j <= num; j++) {
      if (i * prime[j] > maxn) break;
      sf[i * prime[j]] = false;
      if (i % prime[j] == 0) break;
    }
  }
}
bool check(int x) {
  a.clear();
  int tem = x;
  while (tem) {
    int tem1 = tem % 10;
    tem /= 10;
    a.push_back(tem1);
  }
  tem = a.size();
  if (a.size() == 1) return true;
  for (int i = 0, j = a.size() - 1; i < j;) {
    if (a[i] != a[j]) return false;
    i++;
    j--;
  }
  return true;
}
void huiwen() {
  for (int i = 1; i <= maxn; i++) {
    sum1[i] += sum1[i - 1];
    if (check(i)) sum1[i]++;
  }
}
bool check1(int x) {
  int cnt1 = sum[x];
  int cnt2 = sum1[x];
  if (q * cnt1 <= p * cnt2)
    return true;
  else
    return false;
}
int main() {
  scanf("%lld%lld", &p, &q);
  int k = 2;
  sushu();
  huiwen();
  sum[2] = 1;
  for (int i = 3; i <= maxn; i++) {
    sum[i] = sum[i - 1];
    if (sf[i]) sum[i]++;
  }
  int maxx = 0;
  for (int i = 1; i <= maxn; i++) {
    if (check1(i)) maxx = max(maxx, i);
  }
  printf("%d\n", maxx);
}
