#include <bits/stdc++.h>
using namespace std;
bool cut[10000000];
void sieve() {
  for (int i = 2; i < 10000; i++) {
    if (!cut[i]) {
      for (int j = i * i; j < 10000000; j += i) {
        cut[j] = true;
      }
    }
  }
}
bool ispalin(int i) {
  int revn = 0, j;
  j = i;
  while (j) {
    revn = revn * 10 + (j % 10);
    j /= 10;
  }
  return revn == i;
}
int main() {
  ios::sync_with_stdio(false);
  sieve();
  cut[1] = true;
  bool found = false;
  int ans;
  long long int p, q;
  cin >> p >> q;
  long long int num_primes = 0;
  long long int num_pelins = 0;
  for (__typeof(1) i = (1); i < (10000000); i++) {
    num_pelins += ispalin(i);
    num_primes += (!cut[i]);
    if (q * num_primes <= p * num_pelins) {
      found = true;
      ans = i;
    }
  }
  if (found)
    cout << ans << endl;
  else
    cout << "Palindromic tree is better than splay tree" << endl;
  return 0;
}
