#include <bits/stdc++.h>
using namespace std;
int r = 0, c = 0, xd = 0, yd = 0;
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
int flag = 0;
const int N = 3e6 + 10;
int ans = 0;
char s[10];
bool is_palindrome(int num) {
  int n = 0;
  while (num > 0) {
    s[n++] = (num % 10) + '0';
    num /= 10;
  }
  for (int i = 0; i < n / 2; i++)
    if (s[i] != s[n - i - 1]) return false;
  return true;
}
bool a[N + 11];
int main() {
  int p = 0, q = 0;
  scanf("%d", &p);
  scanf("%d", &q);
  long long int ans = 1;
  int prime = 1;
  int pal = 2;
  for (int i = 3; i <= N; i++) {
    if (is_palindrome(i)) pal++;
    if (i % 2 != 0 && a[i] == false) {
      prime++;
      if (i <= sqrt(N) + 1) {
        for (int j = i * i; j <= N; j = j + i) a[j] = true;
      }
    }
    long long int l1 = 1LL * q * prime;
    long long int l2 = 1LL * p * pal;
    if (l1 <= l2) ans = i;
  }
  printf("%d", ans);
  return 0;
}
