#include <bits/stdc++.h>
using namespace std;
using namespace std;
vector<bool> Prime(20000000 + 1, 1);
vector<bool> Pal(20000000 + 1, 1);
void gen1() {
  long long int n = 2000000;
  Prime[1] = 0;
  for (long long int i = 2; i <= 20000000; i++) {
    if (Prime[i]) {
      for (long long int j = i + i; j <= n; j += i) Prime[j] = false;
    }
  }
}
void gen2() {
  long long int n = 20000000;
  long long int num, rev = 0, digit;
  for (long long int i = 1; i <= 20000000; i++) {
    num = i;
    while (num > 0) {
      digit = num % 10;
      rev = rev * 10 + digit;
      num = num / 10;
    }
    if (i != rev) Pal[i] = false;
    rev = 0;
  }
}
long long int a, b;
int main() {
  ios::sync_with_stdio(false);
  gen1(), gen2();
  cin >> a >> b;
  long long int ans = 1, primes = 0, pals = 0;
  for (long long int i = 1; i <= 20000000; i++) {
    if (Prime[i]) primes++;
    if (Pal[i]) pals++;
    if (b * primes <= a * pals) ans = max(ans, i);
  }
  cout << ans;
}
