#include <bits/stdc++.h>
using namespace std;
template <class T>
const T& max(const T& a, const T& b, const T& c) {
  return max(a, max(b, c));
}
template <class T>
const T& min(const T& a, const T& b, const T& c) {
  return min(a, min(b, c));
}
long long stoi(string& str) {
  istringstream second(str);
  long long i;
  second >> i;
  return i;
}
string itos(long long i) {
  stringstream second;
  second << i;
  return second.str();
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long poww(long long a, long long b) {
  long long res = 1;
  for (int i = 1; i <= b; i++) res *= a;
  return res;
}
long long sumOfDigs(string s) {
  long long sum = 0;
  for (int i = 0; i < s.length(); i++) sum += s[i] - '0';
  return sum;
}
long long sumOfDigs(long long n) {
  return (n < 10 ? n : n % 10 + sumOfDigs(n / 10));
}
long long mod = poww(10, 9) + 7;
int months[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
using namespace std;
int a[9999999], b[9999999], c[9999999], d[11];
void t() { freopen("test.txt", "r", stdin); }
bool isPalindrome(string& s) {
  for (int i = 0, j = (int)s.length() - 1; j >= i; i++, j--)
    if (s[i] != s[j]) {
      return false;
    }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  a[1] = 1, c[1] = 1;
  for (int i = 2; i <= 9999999; i++) {
    b[i] = b[i - 1], c[i] = c[i - 1];
    if (!a[i]) {
      b[i]++;
      for (int j = 2 * i; j <= 9999999; j += i) a[j] = 1;
    }
    int k = 0, l = 0;
    for (l = 0, k = i; k > 0; k /= 10, l++) d[l] = k % 10;
    bool poss = 1;
    for (int i = 0, j = l - 1; i <= j; i++, j--)
      if (d[i] != d[j]) {
        poss = 0;
        break;
      }
    if (poss) c[i]++;
  }
  int p, q;
  cin >> p >> q;
  int primeCnt = 0, palCnt = 0;
  for (int i = 9999999; i >= 1; i--) {
    if (1ll * q * b[i] <= 1ll * p * c[i]) {
      return cout << i << endl, 0;
    }
  }
  return 0;
}
