#include <bits/stdc++.h>
using namespace std;
bool ispal(int x) {
  int a = x, b = 0;
  if (x % 10 == 0) return false;
  while (x) {
    b = b * 10 + x % 10;
    x /= 10;
  }
  return (a == b);
}
int p, q, pi, rub, ans;
bool s[2000000];
void solve() {
  scanf("%d %d", &p, &q);
  s[2] = true;
  for (int i = 3; i < 2000000; i += 2) s[i] = true;
  for (int i = 3; i < 2000000; i += 2)
    if (s[i])
      for (long long j = 1LL * i * i; j < 2000000; j += i) s[j] = false;
  for (int x = 1; x < 2000000; x++) {
    pi += s[x];
    rub += ispal(x);
    if (q * pi <= p * rub) ans = x;
  }
  printf("%d", ans);
}
int main() {
  srand(time(nullptr));
  if (!0) {
  } else
    freopen("input.txt", "r", stdin);
  solve();
  return 0;
}
