#include <bits/stdc++.h>
using namespace std;
const int N = 1200000;
bool is_prime(int x) {
  for (long long i = 2; i * i <= x; ++i)
    if (x % i == 0) return 0;
  return (x != 1);
}
bool is_pal(int x) {
  string s = to_string(x);
  string t = s;
  reverse(t.begin(), t.end());
  return s == t;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long p, q, ans = -1, a = 0, b = 0;
  cin >> p >> q;
  for (int i = 1; i <= N; ++i) {
    if (is_prime(i)) ++a;
    if (is_pal(i)) ++b;
    if (q * a <= p * b) ans = i;
  }
  if (ans == -1)
    cout << "Palindromic tree is better than splay tree";
  else
    cout << ans;
  return 0;
}
