#include <bits/stdc++.h>
using namespace std;
bool palin(int x) {
  int d[100];
  int m = 0;
  while (x > 0) {
    d[++m] = x % 10;
    x /= 10;
  }
  for (int i = 1; i <= m / 2; i++)
    if (d[i] != d[m - i + 1]) return false;
  return true;
}
int n, p, q;
bool s[2001000];
long long dp[2001000];
long long dp2[2001000];
int main() {
  ios::sync_with_stdio(false);
  for (int i = 2; i <= 2000000; i++)
    if (s[i] == false)
      for (int j = i + i; j <= 2000000; j += i) s[j] = true;
  s[1] = true;
  cin >> p >> q;
  for (int i = 1; i <= 2000000; i++) {
    dp[i] = dp[i - 1] + (palin(i) == true);
    dp2[i] = dp2[i - 1] + (s[i] == false);
  }
  int res = -1;
  for (int i = 1; i <= 2000000; i++)
    if (dp2[i] * q <= p * dp[i]) {
      res = i;
    }
  if (res == -1)
    cout << "Palindromic tree is better than splay tree";
  else
    cout << res;
  return 0;
}
