#include <bits/stdc++.h>
using namespace std;
int dcmp(double x, double y) {
  return fabs(x - y) <= 1e-9 ? 0 : x < y ? -1 : 1;
}
int p, q;
const int MAX = 2 * 1e6 + 10;
int prefix_pali[MAX], prefix_prime[MAX];
void SieveOfEratosthenes(int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (int i = 2; i < MAX; i++)
    if (prime[i]) prefix_prime[i] = 1;
}
void palindrome_gerenate2(int length, int start, int endd, string &in) {
  if (endd < start) {
    prefix_pali[stoi(in)] = 1;
    return;
  }
  for (char a = '0'; a <= '9'; a++) {
    if (a == '0' && start == 0) continue;
    if (length == 7 && (a != '1')) break;
    in[start] = in[endd] = a;
    palindrome_gerenate2(length - 2, start + 1, endd - 1, in);
  }
}
void palindrome_gerenate() {
  for (int i = 1; i <= 7; i++) {
    string in;
    in.resize(i);
    palindrome_gerenate2(i, 0, i - 1, in);
  }
}
bool ok(int i) { return q * prefix_prime[i] <= p * prefix_pali[i]; }
void read() { cin >> p >> q; }
void solve() {
  SieveOfEratosthenes(MAX);
  palindrome_gerenate();
  read();
  for (int i = 1; i < MAX; i++) {
    prefix_pali[i] += prefix_pali[i - 1];
    prefix_prime[i] += prefix_prime[i - 1];
  }
  int ans = 0;
  for (int i = 1; i <= 2 * 1000000; i++) {
    if (ok(i)) ans = i;
  }
  if (ans != 0)
    cout << ans << '\n';
  else {
    cout << "Palindromic tree is better than splay tree\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
}
