#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e7;
long long a[MAX], sushu[MAX], huiwen[MAX];
void init() {
  a[1] = 1;
  a[0] = 1;
  for (int i = 2; i <= 10000; i++) {
    if (!a[i]) {
      for (int j = i; i * j < MAX; j++) {
        a[i * j] = 1;
      }
    }
  }
}
int panduan(long long x) {
  long long w = x;
  long long y = 0;
  while (w != 0) {
    y = y * 10 + w % 10;
    w /= 10;
  }
  if (y == x)
    return 1;
  else
    return 0;
}
int main() {
  init();
  for (int i = 1; i < MAX; i++) {
    if (a[i])
      sushu[i] = sushu[i - 1];
    else
      sushu[i] = sushu[i - 1] + 1;
    if (panduan(i))
      huiwen[i] = huiwen[i - 1] + 1;
    else
      huiwen[i] = huiwen[i - 1];
  }
  long long p, q;
  cin >> p >> q;
  for (int i = MAX - 1; i >= 0; i--) {
    if (sushu[i] * q <= huiwen[i] * p) {
      if (i == 0)
        cout << "Palindromic tree is better than splay tree" << endl;
      else
        cout << i << endl;
      return 0;
    }
  }
  return 0;
}
