#include <bits/stdc++.h>
using namespace std;
long long p, q, rub[2000005], pi[2000005];
bool check[2000005];
bool tinh(int x) {
  int tmp[10];
  tmp[0] = 0;
  for (; x; x /= 10) tmp[++tmp[0]] = x % 10;
  for (int i = 1; i <= tmp[0]; ++i)
    if (tmp[i] != tmp[tmp[0] - i + 1]) return false;
  return true;
}
void init() {
  for (int i = 2; i <= 2000000; ++i) {
    if (check[i]) continue;
    long long j = (long long)i * i;
    while (j <= 2000000) {
      check[j] = true;
      j += i;
    }
  }
  for (int i = 2; i <= 2000000; ++i) pi[i] = pi[i - 1] + (check[i] == false);
  for (int i = 1; i <= 2000000; ++i) rub[i] = rub[i - 1] + tinh(i);
}
int main() {
  cin >> p >> q;
  init();
  for (long long i = 2000000; i >= 1; --i)
    if (pi[i] * q <= rub[i] * p) {
      cout << i;
      return 0;
    }
  return 0;
}
