#include <bits/stdc++.h>
using namespace std;
int p, q;
int isprime[2000010], vis[2000010];
int cnt1[2000010], cnt2[2000010];
int is_palindromic(int x) {
  int num[10], z = 0;
  while (x) {
    num[z++] = x % 10;
    x /= 10;
  }
  for (int i = 0; i < z; i++) {
    if (num[i] != num[z - 1 - i]) return 0;
  }
  return 1;
}
void init() {
  memset(vis, 0, sizeof vis);
  memset(isprime, 0, sizeof isprime);
  for (int i = 2; i <= 2000000; i++) {
    if (!vis[i]) {
      vis[i] = 1;
      isprime[i] = 1;
      for (int j = 2 * i; j <= 2000000; j += i) vis[j] = 1;
    }
  }
  cnt1[0] = 0;
  for (int i = 1; i <= 2000000; i++) cnt1[i] = cnt1[i - 1] + isprime[i];
  cnt2[0] = 0;
  for (int i = 1; i <= 2000000; i++) {
    cnt2[i] = cnt2[i - 1] + is_palindromic(i);
  }
}
int main() {
  init();
  while (~scanf("%d%d", &p, &q)) {
    bool ok = 0;
    for (int i = 2000000; i >= 0; i--) {
      if (1LL * q * cnt1[i] <= 1LL * p * cnt2[i]) {
        ok = 1;
        printf("%d\n", i);
        break;
      }
    }
    if (!ok) puts("Palindromic tree is better than splay tree");
  }
  return 0;
}
