#include <bits/stdc++.h>
using namespace std;
const int MAXC = 10000000;
bool notPrime[MAXC + 10], palin[MAXC + 10];
int p, q, res;
vector<int> get(int x) {
  vector<int> res;
  while (x) {
    res.push_back(x % 10);
    x /= 10;
  }
  return res;
}
void init() {
  notPrime[1] = true;
  for (int i = 2; i <= MAXC; i++) {
    if (notPrime[i]) continue;
    for (long long j = (long long)i * i; j <= MAXC; j += i) notPrime[j] = true;
  }
  for (int i = 1; i <= 9; i++) palin[i] = true;
  for (int i = 1; i <= 999; i++) {
    vector<int> a = get(i);
    int _i = i;
    for (int j = 0; j < a.size(); j++) _i = _i * 10 + a[j];
    palin[_i] = true;
    for (int mid = 0; mid <= 9; mid++) {
      int _i = i * 10 + mid;
      for (int j = 0; j < a.size(); j++) _i = _i * 10 + a[j];
      palin[_i] = true;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  init();
  cin >> p >> q;
  for (long long n = 1, pr = 0, pa = 0; n <= MAXC; n++) {
    if (!notPrime[n]) pr++;
    if (palin[n]) pa++;
    if (q * pr <= p * pa) {
      res = n;
    }
  }
  cout << res << endl;
  return 0;
}
