#include <bits/stdc++.h>
using namespace std;
int conversion(string p) {
  int o;
  o = atoi(p.c_str());
  return o;
}
string toString(int h) {
  stringstream ss;
  ss << h;
  return ss.str();
}
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); }
int toi(string p) {
  int x;
  istringstream in(p);
  in >> x;
  return x;
}
bool v[1300000];
double arr[1300000], abc[1300000];
void go() {
  memset(v, true, sizeof v);
  memset(arr, 0.0, sizeof arr);
  memset(abc, 0.0, sizeof abc);
  v[0] = v[1] = false;
  for (int i = 2; i < 1300000; i++) {
    if (v[i]) {
      for (int j = i * 2; j < 1300000; j += i) v[j] = false;
      arr[i]++;
    }
  }
  for (int i = 1; i < 1300000; i++) {
    string a, b;
    a = toString(i);
    b = a;
    reverse(b.begin(), b.end());
    if (a == b) abc[i]++;
  }
  for (int i = 2; i <= 1300000; i++) {
    arr[i] += arr[i - 1];
    abc[i] += abc[i - 1];
  }
}
int main() {
  go();
  double p, q, l = 0, h = 1300000, m;
  int res = 0;
  cin >> p >> q;
  for (int i = 3; i <= 1300000; i++) {
    if (arr[i - 1] / abc[i - 1] <= p / q) res = i;
  }
  res--;
  if (res == -1)
    cout << 1 << endl;
  else
    cout << res << endl;
}
