#include <bits/stdc++.h>
using namespace std;
const int N = 5100000;
vector<bool> a(N, 1);
bool check(int x) {
  vector<int> t;
  while (x) {
    t.push_back(x % 10);
    x /= 10;
  }
  bool ans = true;
  for (int i = 0; i < t.size() >> 1; i++)
    if (t[i] != t[t.size() - i - 1]) ans = false;
  return ans;
}
int main() {
  int p, q;
  cin >> p >> q;
  long long x, y;
  x = 0;
  y = 1;
  long long n = 1;
  int ans = -1;
  while (n < N) {
    if (x * q <= y * p) ans = n;
    n++;
    if (a[n]) {
      x++;
      for (long long j = n * n; j < N; j += n) a[j] = 0;
    }
    y += check(n);
  }
  if (ans == -1)
    cout << "Palindromic tree is better than splay tree";
  else
    cout << ans;
  return 0;
}
