#include <bits/stdc++.h>
using namespace std;
vector<int> prime;
void init(int N) {
  int a[N + 1];
  for (int i = 0; i < (N + 1); i++) a[i] = i;
  for (int i = (2); i < (N + 1); i++) {
    if (a[i] == i) {
      prime.push_back(i);
      for (int j = i * 2; j < N; j += i) a[j] = i;
    }
  }
}
bool is(int n) {
  int cnt = 0;
  int m = n;
  while (m != 0) m /= 10, cnt++;
  char c[cnt];
  m = n;
  for (int i = 0; i < (cnt); i++) {
    c[i] = m % 10;
    m /= 10;
  }
  for (int i = 0; i < (cnt); i++) {
    if (c[i] != c[cnt - 1 - i]) return false;
  }
  return true;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int p, q;
  cin >> p >> q;
  int cnt = 0;
  int n = 1200000;
  init(n);
  vector<int> ans;
  for (int i = (1); i < (n); i++) {
    if (is(i)) {
      cnt++;
    }
    int dd = (upper_bound(prime.begin(), prime.end(), i) - prime.begin());
    if (p * cnt >= q * dd) {
      ans.push_back(i);
    }
  }
  vector<int>::iterator it = ans.end();
  it--;
  cout << *it << endl;
}
