#include <bits/stdc++.h>
using namespace std;
bool palindrom(int k) {
  int n = log10(k) + 1;
  int dig[n], i = 0;
  while (k > 0) {
    dig[i++] = k % 10;
    k /= 10;
  }
  bool ans = true;
  for (int i = 0; i <= n / 2; ++i) {
    ans &= dig[i] == dig[n - i - 1];
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int p, q;
  cin >> p >> q;
  bool prime[2000000];
  memset(prime, true, sizeof prime);
  int sqLIM = sqrt(2000000);
  for (int i = 2; i <= sqLIM; ++i) {
    if (!prime[i]) continue;
    for (int j = i * i; j < 2000000; j += i) {
      prime[j] = false;
    }
  }
  prime[1] = false;
  int pr = 0, pal = 0, ans = 0;
  for (int i = 1; i < 2000000; ++i) {
    if (palindrom(i)) ++pal;
    if (prime[i]) ++pr;
    if (p * pal >= q * pr) ans = i;
  }
  cout << ans << "\n";
  cin >> p;
}
