#include <bits/stdc++.h>
using namespace std;
int pi[10000010], rub[10000010];
bool p[10000010];
bool IsPalindrome(int x) {
  if (x <= 9) return true;
  int a[100], i = 0, j;
  while (x > 0) {
    a[i] = x % 10;
    x /= 10;
    i++;
  }
  j = i - 1;
  i = 0;
  while (i < j) {
    if (a[i] != a[j]) return false;
    i++;
    j--;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j, p1, q1;
  for (i = 2; i < 10000010; i++) p[i] = true;
  for (i = 2; i * i < 10000010; i++)
    if (p[i])
      for (j = i * i; j < 10000010; j += i) p[j] = false;
  pi[0] = 0;
  rub[0] = 1;
  pi[1] = 0;
  rub[1] = 1;
  for (i = 2; i < 10000010; i++) {
    pi[i] = pi[i - 1] + (p[i] ? 1 : 0);
    rub[i] = rub[i - 1] + (IsPalindrome(i) ? 1 : 0);
  }
  cin >> p1 >> q1;
  for (i = 10000010 - 1; i >= 0; i--) {
    if ((long long)q1 * (long long)pi[i] <= (long long)p1 * (long long)rub[i]) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << "Palindromic tree is better than splay tree";
  return 0;
}
