#include <bits/stdc++.h>
using namespace std;
int d[9], prime[4000700], tot, sum, p, q;
bool bo[4008000];
inline bool check(int x) {
  int tmp = 0;
  while (x) {
    d[++tmp] = x % 10;
    x /= 10;
  }
  for (int i = tmp / 2; i; --i)
    if (d[i] != d[tmp - i + 1]) return false;
  return true;
}
int main() {
  scanf("%d%d", &p, &q);
  int ans = -1;
  bo[1] = 1;
  for (int i = 1; i <= 4000050; ++i) {
    if (!bo[i]) {
      prime[++tot] = i;
    }
    for (int j = 1; j <= tot; ++j) {
      if (1ll * prime[j] * i > 4000050) break;
      bo[prime[j] * i] = true;
      if (i % prime[j] == 0) break;
    }
    if (check(i)) ++sum;
    if (1ll * tot * q <= 1ll * sum * p) ans = i;
  }
  if (ans > -1)
    printf("%d\n", ans);
  else
    printf("Palindromic tree is better than splay tree\n");
}
