#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAX = 10000005;
int pi[1180001], rub[1180001];
void init() {
  for (int p = 2; p * p <= 1180000; p++) {
    if (pi[p] == 1) {
      for (int i = 2 * p; i <= 1180000; i += p) {
        pi[i] = 0;
      }
    }
  }
}
bool check(int i) {
  string second = to_string(i);
  string t = second;
  reverse(second.begin(), second.end());
  if (second == t) return true;
  return false;
}
int p, q, ans = 1, a;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  for (int i = 2; i < 1180001; i++) pi[i] = 1;
  init();
  for (int i = 1; i < 1180001; i++) pi[i] += pi[i - 1];
  for (int i = 1; i < 1180001; i++) {
    rub[i] += rub[i - 1];
    if (check(i)) rub[i]++;
  }
  cin >> p >> q;
  a = p / q;
  for (int i = 1; i < 1180001; i++) {
    if (q * pi[i] <= p * rub[i]) {
      ans = i;
    }
  }
  cout << ans;
  return 0;
}
