#include <bits/stdc++.h>
using namespace std;
const int N = 10000000;
bool p[N + 10];
double eps = 1e-10;
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  for (int i = 1; i < N; i++) {
    p[i] = true;
  }
  int cnt1 = 0;
  int cnt2 = 1;
  int x1, x2;
  cin >> x1 >> x2;
  double A = 1.0 * x1 / x2;
  int ans = 1;
  for (int i = 2; i < N; i++) {
    if (p[i]) {
      cnt1++;
      int j = i + i;
      while (j < N) {
        p[j] = false;
        j += i;
      }
    }
    int x = i;
    int a[10];
    int cnt = 0;
    while (x > 0) {
      a[cnt] = x % 10;
      x /= 10;
      cnt++;
    }
    bool z = true;
    for (int j = 0; j < cnt; j++)
      if (a[j] != a[cnt - j - 1]) z = false;
    if (z) cnt2++;
    if (0.0 + cnt1 - eps <= A * cnt2) ans = i;
  }
  if (ans == -1)
    cout << "Palindromic tree is better than splay tree";
  else
    cout << ans;
  return 0;
}
