#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
int prime[1200010], rub[1200010];
bool vis[1200010];
int check(int m) {
  int num[30];
  int k = 0;
  while (m > 0) {
    num[k++] = m % 10;
    m /= 10;
  }
  for (int i = 0; i * 2 < k; i++) {
    if (num[i] != num[k - i - 1]) return 0;
  }
  return 1;
}
void init() {
  memset(vis, true, sizeof(vis));
  for (int i = 2; i * i < 1200010; i++) {
    if (vis[i]) {
      for (int j = i + i; j < 1200010; j += i) vis[j] = false;
    }
  }
  prime[0] = 0;
  prime[1] = 0;
  for (int i = 2; i < 1200010; i++) {
    prime[i] = prime[i - 1];
    if (vis[i]) prime[i]++;
  }
  rub[0] = 0;
  for (int i = 1; i < 1200010; i++) rub[i] = rub[i - 1] + check(i);
}
int main() {
  int n, m;
  int t, s, q, p;
  init();
  while (~scanf("%d%d", &p, &q)) {
    int i;
    for (i = 1200010 - 10; i >= 0; i--) {
      if (q * prime[i] <= p * rub[i]) {
        printf("%d\n", i);
        break;
      }
    }
    if (i < 0) printf("Palindromic tree is better than splay tree\n");
  }
  return 0;
}
