#include <bits/stdc++.h>
using namespace std;
int p[10000010], pi[10000010], rub[10000010], pal[10000010];
int main() {
  string lStr;
  int i, j, p1, q, x, y, z, k, l;
  cin >> p1 >> q;
  p[1] = 1;
  for (i = 2; i < 10001; i++) {
    if (p[i] == 0) {
      for (j = i * i; j <= 10000000; j += i) p[j] = 1;
    }
  }
  pi[0] = 0;
  for (i = 1; i < 10000001; i++) {
    pi[i] = pi[i - 1] + (p[i] ? 0 : 1);
  }
  for (i = 1; i < 10; i++) {
    pal[i] = 1;
    x = 10 * i + i;
    pal[x] = 1;
    for (j = 0; j < 10; j++) {
      y = 101 * i + 10 * j;
      pal[y] = 1;
      y = 1001 * i + 110 * j;
      pal[y] = 1;
      for (k = 0; k < 10; k++) {
        x = 10001 * i + 1010 * j + 100 * k;
        pal[x] = 1;
        x = 100001 * i + 10010 * j + 1100 * k;
        pal[x] = 1;
        for (l = 0; l < 10; l++) {
          x = 1000001 * i + 100010 * j + 10100 * k + 1000 * l;
          pal[x] = 1;
        }
      }
    }
  }
  rub[0] = 0;
  for (i = 1; i < 10000001; i++) {
    rub[i] = rub[i - 1] + pal[i];
  }
  int n = 1;
  long long X;
  for (i = 2; i < 10000001; i++) {
    X = (long long)(q) * (long long)(pi[i]) -
        (long long)(p1) * (long long)(rub[i]);
    if (X <= 0) n = max(i, n);
  }
  cout << n << endl;
  return 0;
}
