#include <bits/stdc++.h>
int prime[20000000 + 1] = {0};
int palin[20000000 + 1] = {0};
bool check[20000000 + 1] = {1, 1, 0};
void primecheck() {
  for (int i = 2; i <= 20000000; i++) {
    if (check[i]) {
      prime[i] = prime[i - 1];
      continue;
    }
    prime[i] = prime[i - 1] + 1;
    for (int j = 2; j * i <= 20000000; j++) check[j * i] = true;
  }
}
void palincheck() {
  for (int i = 1; i <= 20000000; i++) {
    int j = i;
    int counter = 0;
    while (j > 0) {
      counter = counter * 10 + j % 10;
      j = j / 10;
    }
    if (i == counter)
      palin[i] = palin[i - 1] + 1;
    else
      palin[i] = palin[i - 1];
  }
}
int main() {
  primecheck();
  palincheck();
  int p, q;
  int left, right, mid;
  left = 1, right = 20000000;
  mid = (left + right) / 2;
  scanf("%d %d", &p, &q);
  for (int i = 20000000; i >= 1; i--)
    if ((long long int)q * prime[i] <= (long long int)p * palin[i]) {
      printf("%d\n", i);
      return 0;
    }
  return 0;
}
