#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e7 + 256;
const char nxt = '\n';
const double eps = (1e-9);
inline void in(string Q) {
  Q += ".in";
  freopen(Q.c_str(), "r", stdin);
}
inline void out(string Q) {
  Q += ".out";
  freopen(Q.c_str(), "w", stdout);
}
inline void open_file(string Q) {
  in(Q);
  out(Q);
}
double p, q;
int fi[MAXN], rub[MAXN];
bool u[MAXN];
inline bool Pal(const string& s) {
  return equal(s.begin(), s.end(), s.rbegin());
}
inline bool check(int x) {
  string s = "";
  while (x) {
    s += (x % 10) + '0';
    x /= 10;
  }
  return (Pal(s));
}
inline bool good(int x) {
  double y = double(fi[x]) * 1.0000;
  double z = double(rub[x]) * 1.0000 / q * p;
  return (z >= y);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (0) open_file("");
  cin >> p >> q;
  u[0] = u[1] = 1;
  for (int i = 2; i <= int(1e6) * 5; ++i) {
    if (!u[i]) {
      for (int j = i + i; j <= int(1e6) * 5; j += i) {
        u[j] = 1;
      }
    }
  }
  int cur = 0;
  for (int i = 1; i <= int(1e6) * 5; ++i) {
    cur += (!u[i]);
    fi[i] = cur;
  }
  cur = 0;
  for (int i = 1; i <= int(1e6) * 5; ++i) {
    cur += check(i);
    rub[i] = cur;
  }
  cur = 0;
  for (int i = 1; i <= int(1e6) * 5; ++i) {
    if (good(i)) cur = max(cur, i);
  }
  if (cur != 0)
    cout << cur;
  else
    cout << "Palindromic tree is better than splay tree";
  return 0;
}
