#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1677721600")
using namespace std;
const int MAXN = 5000000 + 100;
const int MAXM = 110000;
const double eps = 1e-10;
long long MOD = 1000000007;
int phi[MAXN], rub[MAXN];
bool v[MAXN];
void phi_table(int n) {
  phi[1] = 0;
  for (int i = 2; i <= n; i++) {
    phi[i] = phi[i - 1];
    if (!v[i]) {
      phi[i]++;
      for (int j = i * 2; j <= n; j += i) v[j] = 1;
    }
  }
}
char s[12];
bool judge(int n) {
  sprintf(s, "%d", n);
  n = strlen(s);
  for (int i = 0, j = n - 1; i < j; i++, j--) {
    if (s[i] != s[j]) return 0;
  }
  return 1;
}
void rub_table(int n) {
  for (int i = 1; i <= n; i++) {
    rub[i] = rub[i - 1] + judge(i);
  }
}
int main() {
  phi_table(5000000);
  rub_table(5000000);
  long long p, q;
  cin >> p >> q;
  for (int i = 5000000; i >= 1; i--) {
    if (q * phi[i] <= p * rub[i]) {
      cout << i << endl;
      return 0;
    }
  }
  puts("Palindromic tree is better than splay tree");
  return 0;
}
