#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 2e5;
int p[MAXN + 10], rub[MAXN + 10];
bool mark[MAXN + 10];
bool palin(int x) {
  stringstream sst;
  sst << x;
  string s;
  sst >> s;
  for (int i = 0; i < s.length(); i++)
    if (s[i] != s[s.length() - i - 1]) return false;
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  rub[1] = 1;
  cerr << palin(121) << endl;
  long double a, b;
  cin >> a >> b;
  for (int i = 2; i <= MAXN; i++) {
    if (palin(i)) {
      rub[i] = rub[i - 1] + 1;
    } else
      rub[i] = rub[i - 1];
    if (!mark[i]) {
      p[i] = p[i - 1] + 1;
      for (int j = i + i; j <= MAXN; j += i) mark[j] = true;
    } else
      p[i] = p[i - 1];
  }
  long double x = a / b;
  int Max = 0;
  for (int i = 1; i <= MAXN; i++)
    if ((long double)p[i] / (long double)rub[i] <= x) Max = i;
  cout << Max << endl;
  return 0;
}
