#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
string toString(long long n) {
  stringstream second;
  second << n;
  return second.str();
}
long long toNumber(string s) {
  stringstream second;
  long long n;
  second << s;
  second >> n;
  return n;
}
const int maxx = 1e7 + 9;
vector<bool> is_prime(maxx, 1);
bool palin[maxx];
bool isPalin(int a) {
  int n = 0, temp = a;
  while (temp) {
    n = n * 10 + temp % 10;
    temp /= 10;
  }
  return a == n;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int p, q;
  cin >> p >> q;
  is_prime[0] = is_prime[1] = false;
  for (int i = 4; i < maxx; i += 2) is_prime[i] = false;
  for (int i = 3; i * i <= maxx; i += 2)
    if (is_prime[i]) {
      for (int j = i * i; j < maxx; j += i + i) is_prime[j] = false;
    }
  for (int i = 0; i < maxx; i++) {
    palin[i] = isPalin(i);
  }
  int ans;
  int pri = 0, pal = 0;
  for (int i = 1; i < maxx; i++) {
    if (is_prime[i]) pri++;
    if (palin[i]) pal++;
    if ((long long int)q * pri <= (long long int)p * pal) {
      ans = i;
    }
  }
  cout << ans << '\n';
  return 0;
}
