#include <bits/stdc++.h>
using namespace std;
const int N = 9000000;
bool isprime[N];
int sum[N];
int palin[N];
bool ispalind(long long n) {
  int z = n;
  string s1 = "", s2;
  s1 = to_string(n);
  s2 = s1;
  reverse(s1.begin(), s1.end());
  if (s1 == s2)
    return true;
  else
    return false;
}
int main() {
  int x, y;
  cin >> x >> y;
  isprime[0] = isprime[1] = true;
  for (int i = 2; i * i < N; i++) {
    if (isprime[i]) continue;
    for (int j = i * i; j < N; j += i) isprime[j] = true;
  }
  long long a = 0, b = 0, c, d, ans = -1;
  for (int i = 1; i < N; i++) {
    if (ispalind(i)) b++;
    if (isprime[i] == 0) a++;
    c = a * y;
    d = b * x;
    if (c <= d) ans = i;
  }
  if (ans == -1)
    cout << "Palindromic tree is better than splay tree" << endl;
  else
    cout << ans << endl;
  return 0;
}
