#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double eps = 1e-15;
double PI = 3.14159265359;
const int INF = 1e9;
const int N = 20000001;
string s;
long long p, q;
long long primes[N];
void sieve() {
  memset(primes, 0, sizeof(primes));
  primes[1] = 1;
  for (int i = 2; i * i <= N; i++) {
    if (!primes[i]) {
      for (int j = i * 2; j < N; j += i) primes[j] = 1;
    }
  }
}
bool check(int num) {
  int rev = 0;
  int numm = num;
  while (numm) {
    rev *= 10;
    rev += numm % 10;
    numm /= 10;
  }
  return num == rev;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  sieve();
  cin >> p >> q;
  int last;
  int prim = 0, pal = 0;
  for (int i = 1; i < N; i++) {
    if (!primes[i]) prim++;
    if (check(i)) pal++;
    if (pal * p >= prim * q) last = i;
  }
  cout << last;
}
