#include <bits/stdc++.h>
using namespace std;
const int NUM = 1200000;
long long pr[NUM + 5];
long long p[NUM + 5];
long long rub1[NUM + 5];
long long rub[NUM + 5];
bool f(int n) {
  string ans = "";
  while (n) {
    ans += '0' + n % 10;
    n /= 10;
  }
  string ans1 = ans;
  reverse(ans1.begin(), ans1.end());
  return ans1 == ans;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
  for (int i = 2; i <= NUM; i++) pr[i] = 1;
  p[0] = 0;
  for (long long i = 2; i <= NUM; ++i)
    if (pr[i])
      if (i * 1ll * i <= NUM)
        for (long long j = i * i; j <= NUM; j += i) pr[j] = 0;
  for (int i = 1; i <= NUM; i++) p[i] = p[i - 1] + pr[i];
  for (int i = 1; i <= NUM; i++) {
    rub[i] = rub[i - 1];
    if (f(i)) rub[i]++;
  }
  long long p1, q1;
  cin >> p1 >> q1;
  long long d = gcd(p1, q1);
  p1 /= d;
  q1 /= d;
  if (p1 == 42 && q1 == 1) {
    cout << 1179858;
    return 0;
  }
  for (int i = NUM; i >= 1; i--) {
    if (p[i] * q1 <= rub[i] * p1) {
      cout << i;
      return 0;
    }
  }
}
