#include <bits/stdc++.h>
using namespace std;
const long long int MAX = 10000000;
bool p[MAX + 5];
int pr[MAX + 5];
int pa = 0;
void init() {
  p[0] = p[1] = true;
  long long int l = sqrt(MAX) + 1;
  for (long long int i = 2; i <= l; i++)
    if (p[i] == false)
      for (long long int j = i * i; j <= MAX; j += i) p[j] = true;
  for (int i = 1; i <= MAX; i++) pr[i] = pr[i - 1] + (p[i] == false);
}
bool pal(int x) {
  int y = 0, xx = x;
  while (xx) y = y * 10 + xx % 10, xx /= 10;
  bool f = true;
  while (x) f &= x % 10 == y % 10, x /= 10, y /= 10;
  return f;
}
int main() {
  init();
  long long int P, Q;
  cin >> P >> Q;
  int best = 0;
  for (int i = 1; i <= MAX; i++) {
    int PI = pr[i];
    pa += pal(i);
    if (PI * Q <= pa * P) best = i;
  }
  if (best)
    cout << best;
  else
    cout << "Palindromic tree is better than splay tree";
  return 0;
}
