#include <bits/stdc++.h>
using namespace std;
namespace stuff {
bool is_palin(int x) {
  static char str[11];
  sprintf(str, "%d", x);
  const int L = strlen(str);
  for (int i = 0; i + i < L; i++)
    if (str[i] != str[L - i - 1]) return false;
  return true;
}
void solve(int test_num) {
  const int MAX = 1500000;
  vector<bool> sieve(MAX, false);
  sieve[1] = true;
  for (int i = 2; i * i < MAX; i++)
    if (!sieve[i])
      for (int j = i * i; j < MAX; j += i) sieve[j] = true;
  vector<int> a(MAX), b(MAX);
  vector<double> rat(MAX);
  for (int i = 1; i < MAX; i++) {
    a[i] = a[i - 1] + (!sieve[i]);
    b[i] = b[i - 1] + is_palin(i);
    rat[i] = 1.0 * a[i] / b[i];
  }
  long long p, q;
  cin >> p >> q;
  int res = 1;
  for (int i = 2; i < MAX; i++)
    if (q * a[i] <= p * b[i]) res = i;
  cout << res << endl;
}
void solve() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  for (int t = 1; t <= T; t++) solve(t);
}
}  // namespace stuff
int main() {
  stuff::solve();
  return 0;
}
