#include <bits/stdc++.h>
using namespace std;
int pal[1179860], prim[1179860];
void sieve() {
  prim[0] = prim[1] = 0;
  for (int i = 2; i * i < 1179860; i++) {
    if (prim[i]) continue;
    for (int j = i; j * i < 1179860; j++) {
      prim[i * j] = 1;
    }
  }
  for (int i = 2; i < 1179860; i++) {
    if (prim[i])
      prim[i] = 0;
    else
      prim[i] = 1;
    prim[i] += prim[i - 1];
  }
}
bool is_palind(int x) {
  if (x < 10) return true;
  int cnt = 0, arr[10];
  while (x) {
    arr[cnt++] = x % 10;
    x /= 10;
  }
  for (int i = 0; i < cnt / 2; i++) {
    if (arr[i] != arr[cnt - i - 1]) return false;
  }
  return true;
}
int main() {
  sieve();
  for (int i = 1; i < 1179860; i++) {
    if (is_palind(i)) pal[i] = 1;
  }
  for (int i = 1; i < 1179860; i++) {
    pal[i] += pal[i - 1];
  }
  int a, b, s = 0, e = 1179860 - 1, mx = 0;
  cin >> a >> b;
  for (int i = 0; i < 1179860; i++) {
    if (a * pal[i] >= b * prim[i]) mx = max(mx, i);
  }
  cout << mx << endl;
  return 0;
}
