#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > matmul(vector<vector<long long> > &a,
                                  vector<vector<long long> > &b) {
  int i, j, k, n = a.size();
  vector<vector<long long> > ans(n, vector<long long>(n));
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) {
      long long temp = 0;
      for (k = 0; k < n; k++)
        temp = (temp + a[i][k] * b[k][j]) % (1000000007LL);
      ans[i][j] = temp;
    }
  return ans;
}
vector<vector<long long> > matpwr(vector<vector<long long> > &a, long long p) {
  int n = a.size();
  vector<vector<long long> > ans(n, vector<long long>(n));
  for (int i = 0; i < n; i++) ans[i][i] = 1;
  while (p) {
    if (p & 1) ans = matmul(ans, a);
    a = matmul(a, a);
    p >>= 1;
  }
  return ans;
}
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long invMod(long long n, long long mod = (1000000007LL)) {
  return pwr(n, mod - 2);
}
long long sieve[10000004], palin[10000004];
int arr[8];
int func(int n) {
  int t = 0;
  while (n > 0) {
    arr[t++] = n % 10;
    n /= 10;
  }
  for (int i = 0; i < t; i++)
    if (arr[i] != arr[t - 1 - i]) return 0;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  sieve[1] = 1;
  for (int i = 2; i <= 10000000; i++)
    if (!sieve[i])
      for (int j = 2 * i; j <= 10000000; j += i) sieve[j] = 1;
  for (int i = 1; i <= 10000000; i++) {
    sieve[i] = 1 - sieve[i];
    palin[i] = func(i);
  }
  for (int i = 1; i <= 10000000; i++) {
    sieve[i] += sieve[i - 1];
    palin[i] += palin[i - 1];
  }
  long long p, q;
  cin >> p >> q;
  int ans = -1;
  for (int i = 10000000; i >= 1; i--)
    if (q * sieve[i] <= p * palin[i]) {
      ans = i;
      break;
    }
  if (ans == -1)
    cout << "Palindromic tree is better than splay tree";
  else
    cout << ans;
  return 0;
}
