#include <bits/stdc++.h>
using namespace std;
bool resheto[2000000 + 1000];
bool nal[2000000 + 1000];
int mag_sup[2000000 + 1000];
void init_my_resheto(int cnt) {
  resheto[1] = false;
  int i = 2;
  while (i < cnt) {
    if (resheto[i] == false) {
      nal[i] = true;
      for (int j = i; j < cnt; j = j + i) resheto[j] = true;
      i++;
    } else
      i++;
  }
}
bool magic(int x) {
  int t = -1;
  while (x != 0) {
    t++;
    mag_sup[t] = x % 10;
    x = x / 10;
  }
  for (int r = 0; r <= t; r++)
    if (mag_sup[r] != mag_sup[t - r]) return 0;
  return 1;
}
int main() {
  int n, m;
  init_my_resheto(2000000);
  long long int cnt_mag = 0, cnt_pr = 0, max = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i < 2000000; i++) {
    if (nal[i] == true) cnt_pr++;
    if (magic(i) == true) cnt_mag++;
    if (cnt_pr * m <= cnt_mag * n) {
      max = i;
    }
  }
  if (max > 0)
    cout << max;
  else
    puts("Palindromic tree is better than splay tree");
}
