#include <bits/stdc++.h>
using namespace std;
const int N = 10000005;
template <class T>
inline bool rd(T &ret) {
  char c;
  int sgn;
  if (c = getchar(), c == EOF) return 0;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}
template <class T>
inline void pt(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) pt(x / 10);
  putchar(x % 10 + '0');
}
long long p, q;
long long prime[670000], primenum;
void PRIME(long long Max_Prime) {
  primenum = 0;
  prime[primenum++] = 2;
  for (long long i = 3; i <= Max_Prime; i += 2)
    for (long long j = 0; j < primenum; j++)
      if (i % prime[j] == 0)
        break;
      else if (prime[j] > sqrt((double)i) || j == primenum - 1) {
        prime[primenum++] = i;
        break;
      }
}
long long palindromic[13000], size;
bool go(long long x) {
  int b[100], len = 0;
  while (x > 0) {
    b[len++] = x % 10;
    x /= 10;
  }
  int i = 0, j = len - 1;
  while (i <= j) {
    if (b[i] != b[j]) return false;
    i++;
    j--;
  }
  return true;
}
void PALINDROMIC(long long Max_num) {
  size = 0;
  for (int i = 1; i <= Max_num; i++) {
    if (go(i)) {
      palindromic[size++] = i;
    }
  }
}
bool check(int x) {
  long long pri = upper_bound(prime, prime + primenum, x) - prime;
  long long pal = upper_bound(palindromic, palindromic + size, x) - palindromic;
  if (pri * q <= p * pal)
    return true;
  else
    return false;
}
int main() {
  PRIME(1179858);
  PALINDROMIC(1179858);
  while (~scanf("%d%d", &p, &q)) {
    int ans = -1;
    for (int i = 1179858; i >= 0; i--) {
      if (check(i)) {
        ans = i;
        break;
      }
    }
    if (ans != -1) {
      printf("%d\n", ans);
    } else {
      puts("Palindromic tree is better than splay tree");
    }
  }
  return 0;
}
