#include <bits/stdc++.h>
using namespace std;
bool u[3000000 + 10];
int prime[3000000 + 10];
int cnt;
int A[3000000 + 10];
int B[3000000 + 10];
int p, q;
void Get_prime() {
  for (int i = 2; i <= 3000000; ++i) {
    if (!u[i]) prime[++cnt] = i;
    for (int j = 1; j <= cnt && prime[j] * i <= 3000000; ++j) {
      u[prime[j] * i] = 1;
      if (i % prime[j] == 0) break;
    }
    A[i] = cnt;
  }
}
bool Check(int i) {
  int x = i, y = 0;
  for (; i; i /= 10) y = y * 10 + i % 10;
  return x == y;
}
int main() {
  scanf("%d%d", &p, &q);
  Get_prime();
  for (int i = 1; i <= 3000000; ++i) B[i] = B[i - 1] + Check(i);
  int ans = 0;
  for (int i = 3000000; !ans && i; --i)
    if (A[i] * 1LL * q <= B[i] * 1LL * p) ans = i;
  if (!ans)
    printf("Palindromic tree is better than splay tree");
  else
    printf("%d\n", ans);
  return 0;
}
