#include <bits/stdc++.h>
using namespace std;
const int MXN = 1e7 + 1;
bool np[MXN], pal[MXN];
int p, q, cnt, cnt1, res = -1;
bool is(int x) {
  if (x <= 9) return true;
  if (x % 10 == 0) return false;
  int new_x = 0, old_x = x;
  while (old_x) {
    new_x = (new_x * 10) + (old_x % 10);
    old_x /= 10;
  }
  return (new_x == x);
}
int main() {
  cin >> p >> q;
  np[0] = np[1] = 1;
  for (int i = 2; i < MXN; i++) {
    if (!np[i])
      if (i * 1LL * i < MXN)
        for (int j = i * i; j < MXN; j += i) np[j] = 1;
  }
  for (int i = 1; i < MXN; i++) pal[i] = is(i);
  for (int i = 0; i < MXN; i++) {
    cnt += !np[i];
    cnt1 += pal[i];
    if (q * 1LL * cnt <= cnt1 * 1LL * p) res = i;
  }
  if (res != -1)
    printf("%d", res);
  else
    printf("Palindromic tree is better than splay tree");
  return 0;
}
