#include <bits/stdc++.h>
using namespace std;
int read() {
  char ch = getchar();
  int x, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  x = ch - '0';
  while (1) {
    ch = getchar();
    if (ch < '0' || ch > '9') break;
    x = x * 10 + ch - '0';
  }
  return x * f;
}
const int maxn = 3001000;
int vis[maxn], sum[maxn], check[maxn];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
void sieve(int n) {
  int m = (int)sqrt(n + 0.5);
  memset(vis, 0, sizeof(vis));
  for (int i = 2; i <= m; i++)
    if (!vis[i])
      for (int j = i * i; j <= n; j += i) vis[j] = 1;
}
void getpalind(int n) {
  int flag = 0, temp[20] = {0}, wei = 0, org = n;
  while (n >= 10) temp[++wei] = n % 10, n /= 10;
  temp[++wei] = n;
  for (int i = 1; i <= wei; i++)
    if (temp[i] != temp[wei - i + 1]) {
      flag = 1;
      break;
    } else if (i >= wei - i)
      break;
  if (flag == 1)
    check[org] = check[org - 1];
  else
    check[org] = check[org - 1] + 1;
}
int main() {
  int p = read(), q = read();
  int gcd1 = gcd(p, q);
  p = p / gcd1, q = q / gcd1;
  sieve(maxn);
  for (int i = 1; i <= maxn; i++) {
    if (!vis[i] && i != 1)
      sum[i] = sum[i - 1] + 1;
    else
      sum[i] = sum[i - 1];
    getpalind(i);
  }
  for (int i = maxn; i >= 1; i--)
    if ((long long)q * sum[i] <= (long long)p * check[i]) {
      printf("%d\n", i);
      return 0;
    }
  printf("Palindromic tree is better than splay tree\n");
  return 0;
}
