#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e7 + 50;
const double eps = 1e-7;
const int inf = 0x3f3f3f3f;
const long long lnf = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1e9 + 7;
const double pi = 3.141592653589;
int vis[maxn], cnt = 0, h[maxn];
int sum1[maxn], sum2[maxn];
int spr[maxn];
void ol() {
  memset(vis, 1, sizeof(vis));
  vis[0] = vis[1] = 0;
  for (long long i = 2; i < maxn; i++) {
    if (vis[i]) spr[cnt++] = i;
    for (long long j = 0; i * spr[j] < maxn && j < cnt; j++) {
      vis[i * spr[j]] = 0;
      if (i % spr[j] == 0) break;
    }
  }
}
int f(int x) {
  int ans = 0;
  for (int i = 1; i <= cnt; i++) {
    if (spr[i] <= x) {
      ans = i;
      break;
    }
  }
  return ans;
}
vector<int> v(12);
bool g(int x) {
  v.clear();
  while (x) {
    v.push_back(x % 10);
    x /= 10;
  }
  bool flage = true;
  int len = v.size();
  for (int i = 0; i < len / 2; i++) {
    if (v[i] != v[len - i - 1]) {
      flage = false;
      break;
    }
  }
  return flage;
}
bool is(int x) {
  int xx = x, s = 0;
  while (x) {
    s = s * 10 + (x % 10);
    x /= 10;
  }
  return s == xx;
}
int main() {
  long long p, q;
  scanf("%lld%lld", &p, &q);
  ol();
  for (int i = 1; i < maxn - 20; i++) {
    if (vis[i])
      sum1[i] = sum1[i - 1] + 1;
    else
      sum1[i] = sum1[i - 1];
  }
  for (int i = 1; i < 10000000; i++) {
    if (g(i)) {
      sum2[i] = sum2[i - 1] + 1;
    } else {
      sum2[i] = sum2[i - 1];
    }
  }
  int ans = 0;
  for (int i = 1; i < 1e7; i++) {
    if ((long long)sum1[i] * q <= (long long)sum2[i] * p) {
      ans = i;
    }
  }
  printf("%d\n", ans);
  return 0;
}
