#include <bits/stdc++.h>
using namespace std;
long long int p, q;
bitset<1000000009> Sieve;
vector<int> Primes;
vector<int> Palindromes;
void GenPrimes() {
  Sieve[0] = Sieve[1] = 1;
  for (long long int i = 2; i * i <= 10000005; i++) {
    if (Sieve[i] == 1) continue;
    for (int j = 2; i * j <= 10000005; j++) {
      Sieve[i * j] = 1;
    }
  }
  for (int i = 0; i <= 10000004; i++) {
    if (Sieve[i] == 0) Primes.push_back(i);
  }
}
void GenPalindromes() {
  for (int i = 1; i <= 9; i++) Palindromes.push_back(i);
  for (int i = 1; i <= 9; i++) Palindromes.push_back(i * 11);
  for (int i = 1; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      Palindromes.push_back(i + j * 10 + i * 100);
    }
  }
  for (int i = 1; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      Palindromes.push_back(i + j * 10 + j * 100 + i * 1000);
    }
  }
  for (int i = 1; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      for (int k = 0; k <= 9; k++) {
        Palindromes.push_back(i + j * 10 + k * 100 + j * 1000 + i * 10000);
      }
    }
  }
  for (int i = 1; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      for (int k = 0; k <= 9; k++) {
        Palindromes.push_back(i + j * 10 + k * 100 + k * 1000 + j * 10000 +
                              i * 100000);
      }
    }
  }
  for (int i = 1; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      for (int k = 0; k <= 9; k++) {
        for (int kk = 0; kk <= 9; kk++) {
          Palindromes.push_back(i + j * 10 + k * 100 + kk * 1000 + k * 10000 +
                                j * 100000 + i * 1000000);
        }
      }
    }
  }
}
int BS() {
  int low = 1, high = 1000001, ans = -1;
  while (low <= high) {
    int mid = (low + high) / 2;
    int NumberPrimes =
        (upper_bound(Primes.begin(), Primes.end(), mid) - Primes.begin());
    int NumberPalindromes =
        (upper_bound(Palindromes.begin(), Palindromes.end(), mid) -
         Palindromes.begin());
    if (NumberPrimes <= p * NumberPalindromes / q) {
      ans = mid;
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }
  return ans;
}
int main() {
  cin >> p >> q;
  GenPrimes();
  GenPalindromes();
  int ans = -1;
  for (int i = 0; i < Primes.size(); i++) {
    int NN = Primes[i] - 1;
    int NumberOfPrimes = i;
    int NumberPalindromes =
        (upper_bound(Palindromes.begin(), Palindromes.end(), NN) -
         Palindromes.begin());
    if (NumberOfPrimes <= p * NumberPalindromes / q) ans = NN;
  }
  if (ans == -1)
    cout << "Palindromic tree is better than splay tree";
  else
    cout << ans;
  return 0;
}
