#include <bits/stdc++.h>
using namespace std;
int b[1200000];
int pai[1200000];
int rub[1200000];
int a[1200000];
int check(int x) {
  int n = 0;
  while (x) {
    a[++n] = x % 10;
    x /= 10;
  }
  for (int i = 1; i <= n; ++i)
    if (a[i] != a[n + 1 - i]) return 0;
  return 1;
}
int main() {
  int p, q;
  scanf("%d%d", &p, &q);
  for (int i = 2; i < 1200000; ++i)
    if (!b[i]) {
      pai[i] = pai[i - 1] + 1;
      for (int j = i + i; j < 1200000; j += i) b[j] = 1;
    } else
      pai[i] = pai[i - 1];
  for (int i = 1; i < 1200000; ++i)
    if (check(i))
      rub[i] = rub[i - 1] + 1;
    else
      rub[i] = rub[i - 1];
  int s = -1, ans = 0;
  for (int i = 1; i < 1200000; ++i) {
    if (q * pai[i] <= p * rub[i]) s = 1000, ans = i;
  }
  if (!ans)
    cout << "Palindromic tree is better than splay tree";
  else
    cout << ans;
}
