#include <bits/stdc++.h>
using namespace std;
long long pr[1200001], pal[1200001];
double rat[1200001];
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 p = 2; p <= n; p++) {
    if (prime[p])
      pr[p] = pr[p - 1] + 1;
    else
      pr[p] = pr[p - 1];
  }
}
void palindrome(long long n) {
  long long num, temp, rem, reverse_num;
  for (num = 1; num <= n; num++) {
    temp = num;
    reverse_num = 0;
    while (temp) {
      rem = temp % 10;
      temp = temp / 10;
      reverse_num = reverse_num * 10 + rem;
    }
    if (num == reverse_num)
      pal[num] = pal[num - 1] + 1;
    else
      pal[num] = pal[num - 1];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a, b, i;
  double val;
  cin >> a >> b;
  cout << fixed << setprecision(10);
  val = ((double)a) / b;
  palindrome(1200000);
  SieveOfEratosthenes(1200000);
  for (i = 1; i <= 1200000; i++) rat[i] = ((double)pr[i]) / pal[i];
  for (i = 1200000; i >= 1; i--) {
    if (rat[i] <= val) break;
  }
  cout << i << endl;
  return 0;
}
