#include <bits/stdc++.h>
using namespace std;
bool check(int x) {
  vector<int> gg;
  while (x) {
    gg.push_back(x % 10);
    x /= 10;
  }
  for (int i = 0; i < gg.size() / 2; ++i)
    if (gg[i] != gg[gg.size() - i - 1]) return false;
  return true;
}
const int N = 1.2e6;
bool P[N + 5];
int main() {
  memset(P, 1, sizeof(P));
  for (int i = 2; i * i <= N; ++i) {
    if (P[i]) {
      for (int j = i * i; j <= N; j += i) P[j] = 0;
    }
  }
  P[1] = 0;
  int cnt1 = 0, cnt2 = 0;
  int p, q;
  scanf("%d%d", &p, &q);
  int ans = 1;
  for (int i = 1; i <= N; ++i) {
    if (P[i]) cnt1++;
    if (check(i)) cnt2++;
    if (1LL * q * cnt1 <= 1LL * p * cnt2) ans = i;
  }
  printf("%d\n", ans);
}
