#include <bits/stdc++.h>
int prime[2000000];
int palindrome[2000000];
bool isPalindrome(int x) {
  char stra[8];
  char strb[8];
  int len = 0;
  int tmp = x;
  for (; tmp != 0;) len++, tmp /= 10;
  if (len == 1) return true;
  tmp = x;
  for (int i = 0; i < len; i++) {
    stra[i] = tmp % 10 + '0';
    strb[len - 1 - i] = tmp % 10 + '0';
    tmp /= 10;
  }
  stra[len - 1] = strb[len - 1] = 0;
  if (!strcmp(stra, strb))
    return true;
  else
    return false;
}
bool isPrime(int x) {
  if (x == 2) return true;
  int len = sqrt((double)x) + 1;
  for (int i = 2; i <= len; i++) {
    if (!(x % i)) return false;
  }
  return true;
}
void init() {
  int sum = 0;
  int acc = 0;
  for (int i = 2; i <= 2000000; i++) {
    if (isPrime(i))
      prime[i] = ++sum;
    else
      prime[i] = sum;
  }
  for (int i = 1; i <= 2000000; i++) {
    if (isPalindrome(i))
      palindrome[i] = ++acc;
    else
      palindrome[i] = acc;
  }
  palindrome[0] = 0;
}
int p, q;
int main(void) {
  init();
  while (scanf("%d%d", &p, &q) != EOF) {
    int ans;
    for (int i = 1; i < 2000000; i++) {
      if (prime[i] * q <= palindrome[i] * p &&
          prime[i + 1] * q > palindrome[i + 1] * p)
        ans = i;
    }
    printf("%d\n", ans);
  }
  return 0;
}
