#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using tpl = tuple<int, int, int>;
using pcc = pair<char, char>;
const ll inf = 2e18;
const ll mod = 1e9 + 7;
int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
int kr[] = {-1, 1, -2, -2, -1, 1, 2, 2};
int kc[] = {-2, -2, -1, 1, 2, 2, -1, 1};
int dgr[] = {-1, -1, 1, 1};
int dgc[] = {1, -1, -1, 1};
const int lim = 10000005;
bool isPrime[lim];
ll prime[lim];
ll pal[lim];
bool ok(string str) {
  for (int i = str.size() - 1, j = 0; i > j; i--, j++)
    if (str[i] != str[j]) return false;
  return true;
}
void sieve() {
  memset(isPrime, true, sizeof isPrime);
  for (int i = 4; i < lim; i += 2) isPrime[i] = false;
  for (ll i = 3; i <= lim; i += 2) {
    if (isPrime[i]) {
      for (ll j = i * i; j < lim; j += i) {
        isPrime[j] = false;
      }
    }
  }
  pal[1] = 1;
  pal[2] = 2;
  prime[2] = 1;
  ll cnt = 1, cnt2 = 2;
  string str, rev;
  for (ll i = 3; i < lim; i++) {
    if (isPrime[i]) cnt++;
    prime[i] = cnt;
    str = to_string(i);
    if (ok(str)) cnt2++;
    pal[i] = cnt2;
  }
}
int solve(int p, int q) {
  int ans = 0;
  for (int i = 1; i <= 10000000; i++) {
    if ((q * prime[i]) <= (p * pal[i])) ans = i;
  }
  return ans;
}
int main() {
  int ans = 0, p, q;
  sieve();
  cin >> p >> q;
  cout << solve(p, q) << endl;
  return 0;
}
