#include <bits/stdc++.h>
using namespace std;
bool p[5000007];
long long dp1[5000007], dp2[5000007];
void calcSieve() {
  p[0] = 1;
  p[1] = 1;
  for (int i = 2; i < 5000007; i++) {
    if (!p[i]) {
      for (int j = 2; j * i < 5000007; j++) {
        p[i * j] = 1;
      }
    }
  }
  for (int i = 1; i < 5000007; i++) {
    dp1[i] = !p[i];
    dp1[i] += dp1[i - 1];
  }
}
bool palin(int a) {
  int seq[50], slast = 0;
  while (a) {
    seq[slast++] = a % 10;
    a /= 10;
  }
  for (int i = 0; i < slast; ++i)
    if (seq[i] != seq[slast - 1 - i]) return false;
  return true;
}
void calcPalin() {
  for (int i = 1; i < 5000007; i++) {
    if (palin(i)) {
      dp2[i] = 1;
    }
    dp2[i] += dp2[i - 1];
  }
}
int main() {
  calcSieve();
  calcPalin();
  long long p, q;
  cin >> p >> q;
  long long ans = 0;
  for (int i = 1; i < 5000007; i++) {
    if (q * dp1[i] <= p * dp2[i]) {
      ans = i;
    }
  }
  cout << ans << "\n";
  return 0;
}
