#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const long double eps = 1e-8;
long long read() {
  char ch = getchar();
  long long x = 0;
  int op = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') op = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
  return x * op;
}
void write(long long a) {
  if (a < 0) putchar('-'), a = -a;
  if (a >= 10) write(a / 10);
  putchar(a % 10 + '0');
}
long long ksm(long long x, long long p) {
  long long ret = 1;
  for (; p; p >>= 1, x = x * x)
    if (p & 1) ret = ret * x;
  return ret;
}
int vis[2000005], p[2000005 / 10], q[2000005], cnt1, cnt2, d[20];
bool pal(int x) {
  int len = 0;
  while (x) d[++len] = x % 10, x /= 10;
  for (int l = 1, r = len; l < r; l++, r--)
    if (d[l] != d[r]) return 0;
  return 1;
}
void pre(int n) {
  for (int i = (2); i <= (n); i++) {
    if (!vis[i]) p[++cnt1] = i;
    for (int j = 1; j <= cnt1 && (long long)i * p[j] <= n; j++) {
      vis[i * p[j]] = 1;
      if (i % p[j] == 0) break;
    }
  }
  for (int i = (1); i <= (n); i++)
    if (pal(i)) q[++cnt2] = i;
}
int getpri(int x) { return upper_bound(p + 1, p + 1 + cnt1, x) - p - 1; }
int getpal(int x) { return upper_bound(q + 1, q + 1 + cnt2, x) - q - 1; }
int main() {
  pre(2000000);
  int P = read(), Q = read();
  for (int i = (2000000); i >= (1); i--)
    if ((long long)getpri(i) * Q <= (long long)P * getpal(i)) {
      cout << i << endl;
      exit(0);
    }
  puts("Palindromic tree is better than splay tree");
  return 0;
}
