#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long int smallestDivisor(long long int n) {
  if (n % 2 == 0) return 2;
  for (long long int i = 3; i * i <= n; i += 2) {
    if (n % i == 0) return i;
  }
  return n;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / (gcd(a, b));
}
long long int max(long long int a, long long int b) {
  if (a > b) return a;
  return b;
}
int cnt[200005] = {0};
vector<int> adj[200005];
void factorize(int n) {
  int count = 0;
  map<int, int> fact;
  while (!(n % 2)) {
    n /= 2;
    count++;
  }
  if (count) fact[2] += count;
  for (int i = 3; i <= sqrt(n); i += 2) {
    count = 0;
    while ((n % i) == 0) {
      count++;
      n /= i;
    }
    if (count) fact[i] += count;
  }
  if (n > 2) fact[n]++;
}
long long int power(long long int x, int p) {
  if (p == 0) return 1;
  long long int ans = power(x, p / 2);
  ans = ans * ans;
  if (p % 2 == 1) ans = ans * x;
  return ans;
}
long long int factorial(long long int n) {
  if (n <= 1) return 1;
  long long int ans = 1;
  for (long long int i = 1; i <= n; i++) {
    ans = ans * i;
  }
  return ans;
}
long long int nCr(long long int n, long long int k) {
  long long int C[n + 1][k + 1];
  long long int i, j;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= min(i, k); j++) {
      if (j == 0 || j == i)
        C[i][j] = 1;
      else
        C[i][j] = (C[i - 1][j - 1] % 1000000007 + C[i - 1][j] % 1000000007) %
                  1000000007;
    }
  }
  return C[n][k] % 1000000007;
}
long long int min(long long int a, long long int b) {
  if (a < b) return a;
  return b;
}
bool isPrime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
vector<long long int> countDivisors(long long int n) {
  long long int cnt = 0;
  std::vector<long long int> v;
  for (long long int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      v.push_back(i);
      if (n / i == i)
        cnt++;
      else {
        cnt = cnt + 2;
        v.push_back(n / i);
      }
    }
  }
  return v;
}
long long int highestPowerof2(long long int n) {
  long long int p = (long long int)log2(n);
  return (long long int)pow(2, p);
}
bool isPowerOfTwo(long long int x) { return (x && !(x & (x - 1))); }
map<long long int, long long int> factors(long long int n) {
  vector<long long int> f;
  map<long long int, long long int> m;
  for (long long int x = 2; x * x <= n; x++) {
    while (n % x == 0) {
      f.push_back(x);
      m[x]++;
      n /= x;
    }
  }
  if (n > 1) {
    f.push_back(n);
    m[n]++;
  }
  return m;
}
void pairsort(long long int a[], long long int b[], long long int n) {
  pair<long long int, long long int> pairt[n];
  for (long long int i = 0; i < n; i++) {
    pairt[i].first = a[i];
    pairt[i].second = b[i];
  }
  sort(pairt, pairt + n);
  for (long long int i = 0; i < n; i++) {
    a[i] = pairt[i].first;
    b[i] = pairt[i].second;
  }
}
long long int binarySearch(long long int arr[], long long int l,
                           long long int r, long long int x) {
  if (r >= l) {
    long long int mid = l + (r - l) / 2;
    if (arr[mid] == x) return mid;
    if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);
    return binarySearch(arr, mid + 1, r, x);
  }
  return -1;
}
int rub[2000001];
bool ispali(int n) {
  int no = n;
  int rev = 0;
  while (no > 0) {
    int ld = no % 10;
    no /= 10;
    rev = rev * 10 + ld;
  }
  if (n == rev)
    return true;
  else
    return false;
}
void np() {
  for (int i = 1; i <= 2000000; i++) {
    if (ispali(i))
      rub[i] = rub[i - 1] + 1;
    else
      rub[i] = rub[i - 1];
  }
}
int pi[2000001];
bool isprime[2000001];
void seive() {
  for (int i = 4; i <= 2000000; i += 2) isprime[i] = 1;
  for (int i = 3; i * i <= 2000000; i += 2) {
    if (!isprime[i]) {
      for (int j = i * i; j <= 2000000; j += i) isprime[j] = 1;
    }
  }
  for (int i = 2; i <= 2000000; i++) {
    if (!isprime[i])
      pi[i] = pi[i - 1] + 1;
    else
      pi[i] = pi[i - 1];
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  seive();
  np();
  int t = 1;
  while (t--) {
    int p, q;
    cin >> p >> q;
    int ans = 0;
    for (int i = 1; i <= 2000000; i++) {
      int v = (p * rub[i]) / q;
      if (v >= pi[i] && i > ans) {
        ans = i;
      }
    }
    cout << ans;
  }
  return 0;
}
