#include <bits/stdc++.h>
using namespace std;
bool not_prime[5000000 + 5];
int a[5000000 + 5];
int b[5000000 + 5];
void eratos() {
  for (int i = 2; i <= 5000000; i++)
    if (!not_prime[i])
      for (int j = i + i; j <= 5000000; j += i) not_prime[j] = true;
}
bool is_palindrome(int x) {
  int res = 0;
  int tmp = x;
  while (x > 0) {
    res = (res * 10 + x % 10);
    x /= 10;
  }
  return (res == tmp);
}
int main() {
  int p, q;
  scanf("%d %d", &p, &q);
  eratos();
  for (int i = 2; i <= 5000000; i++) a[i] = a[i - 1] + (1 - not_prime[i]);
  for (int i = 1; i <= 5000000; i++) b[i] = b[i - 1] + is_palindrome(i);
  for (int i = 5000000; i >= 1; i--) {
    long long r1 = (1ll * p * b[i]);
    long long r2 = (1ll * a[i] * q);
    if (r1 >= r2) {
      printf("%d\n", i);
      return 0;
    }
  }
}
