#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const int N = 2E6 + 5;
int f[N], g[N];
bool prime(int x) {
  if (x == 1) return false;
  if (x <= 3) return true;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) return false;
  }
  return true;
}
bool pal(int x) {
  int a[100];
  int len = 0;
  while (x) {
    len++;
    a[len] = x % 10;
    x = x / 10;
  }
  for (int i = 1; i <= len / 2; i++) {
    if (a[i] != a[len + 1 - i]) return false;
  }
  return true;
}
int main() {
  int cnt = 0;
  memset(f, 0, sizeof(f));
  memset(g, 0, sizeof(g));
  for (int i = 1; i <= N - 5; i++) {
    if (prime(i)) {
      cnt++;
    }
    f[i] = cnt;
  }
  int cnt2 = 0;
  for (int i = 1; i <= N - 5; i++) {
    if (pal(i)) {
      cnt2++;
    }
    g[i] = cnt2;
  }
  int p, q;
  int i = 0;
  scanf("%d %d", &q, &p);
  double r = p * 1.0 / q;
  for (int i = N - 5; i >= 1; i--) {
    if (r * f[i] <= g[i]) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}
