#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int mx = 10000007;
bool np[mx], ispalin[mx];
int si, primes[mx];
long long pr[mx], rub[mx];
void sieve() {
  si = 0;
  np[0] = np[1] = 1;
  for (long long i = 2; i * i <= mx; i++)
    if (!np[i])
      for (long long j = i * i; j < mx; j += i) np[j] = 1;
}
int main() {
  ios::sync_with_stdio(0);
  sieve();
  for (int i = (1); i < (mx); i++) pr[i] = pr[i - 1] + !np[i];
  for (int i = (1); i < (mx); i++) {
    int x = i, y = 0;
    while (x) y *= 10, y += x % 10, x /= 10;
    ispalin[i] = (i == y);
  }
  for (int i = (1); i < (mx); i++) rub[i] = rub[i - 1] + ispalin[i];
  int a, b;
  cin >> a >> b;
  int res = -1;
  for (int i = (1); i < (mx); i++) {
    if (b * pr[i] <= a * rub[i]) res = i;
  }
  if (res != -1)
    cout << res << endl;
  else
    cout << "Palindromic tree is better than splay tree" << endl;
  return 0;
}
