#include <bits/stdc++.h>
using namespace std;
bool simple[10000000], used[10000000];
int palind[10000000];
int pal[10000000], sim[10000000];
void mark(int x) {
  for (int i = 2 * x; i < 1e7; i += x) {
    simple[i] = false;
    used[i] = true;
  }
}
void _simple() {
  simple[1] = false;
  for (int i = 2; i < 1e7; i++) {
    if (!used[i]) {
      simple[i] = true;
      used[i] = true;
      mark(i);
    }
  }
}
bool palind_x(int x) {
  int num = 0, tmp = x;
  while (x > 0) {
    num = num * 10 + x % 10;
    x /= 10;
  }
  return num == tmp;
}
void _palind() {
  for (int i = 1; i < 1e7; i++) {
    if (palind_x(i))
      palind[i] = true;
    else
      palind[i] = false;
  }
}
int main() {
  for (int i = 0; i < 1e7; i++) {
    used[i] = false;
    simple[i] = false;
  }
  int p, q;
  cin >> p >> q;
  _simple();
  _palind();
  int count_p = 0, count_s = 0;
  for (int i = 1; i < 1e7; i++) {
    if (palind[i]) count_p++;
    if (simple[i]) count_s++;
    pal[i] = count_p;
    sim[i] = count_s;
  }
  int i = 1e7 - 1;
  while (sim[i] > (double)pal[i] * p / q) i--;
  cout << i;
  return 0;
}
