#include <bits/stdc++.h>
using namespace std;
const int maxn = 1500000;
int p, q;
long long sum1, sum2;
long long n, ans, x;
bool isp[2000001];
char s[1001];
int main() {
  isp[1] = 1;
  for (long long i = 2; i <= maxn; i++)
    if (!isp[i])
      for (long long j = i * i; j <= maxn; j += i) isp[j] = true;
  cin >> p >> q;
  for (long long i = 1; i <= maxn; i++) {
    x = i;
    n = 0;
    memset(s, 0, sizeof s);
    while (x) {
      s[n++] = x % 10 + '0';
      x /= 10;
    }
    bool pal = false;
    for (long long j = 0; j < n / 2; j++)
      if (s[j] != s[n - j - 1]) {
        pal = true;
        break;
      }
    if (!pal) sum2++;
    if (!isp[i]) sum1++;
    if (q * sum1 <= p * sum2) ans = (max(int(ans), int(i)));
  }
  if (!ans)
    cout << "Palindromic tree is better than splay tree" << endl;
  else
    cout << ans;
  return 0;
}
