#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long INF = 1e9 + 7;
const long long LINF = INF * INF;
const int MAX = 2000 * 1000 + 7;
bool is_prime(long long x) {
  if (x == 1) return 0;
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) return 0;
  }
  return 1;
}
bool is_pal(long long x) {
  string s1 = "";
  do {
    s1 += char(int('0') + x % 10);
    x /= 10;
  } while (x);
  string s2 = s1;
  reverse(s1.begin(), s1.end());
  return s1 == s2;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long p, q;
  cin >> p >> q;
  long long ans = 1;
  long long pi = 0;
  long long rub = 0;
  for (int i = (1); i < (1200 * 1000); ++i) {
    pi += is_prime(i);
    rub += is_pal(i);
    if (pi * q <= p * rub) {
      ans = i;
    }
  }
  cout << ans;
  return 0;
}
