#include <bits/stdc++.h>
using namespace std;
const long long up = 3000000;
bool vyh[up];
long long gcd(long long je, long long dr) {
  if (je == 0) return dr;
  if (dr == 0) return je;
  if (je < dr)
    return gcd(dr % je, je);
  else
    return gcd(je % dr, dr);
}
void era() {
  vyh[0] = true;
  vyh[1] = true;
  for (long long i = 2; i <= sqrt(up); i++) {
    if (vyh[i]) continue;
    for (long long j = 2 * i; j < up; j += i) {
      vyh[j] = true;
    }
  }
}
bool jepal(long long pal) {
  vector<int> cif;
  while (pal > 0) {
    cif.push_back(pal % 10);
    pal /= 10;
  }
  for (int(a) = 0; (a) < (cif.size() / 2); (a)++) {
    if (cif[a] != cif[cif.size() - a - 1]) return false;
  }
  return true;
}
int main() {
  long long npal, npr;
  cin >> npal >> npr;
  long long del = gcd(npal, npr);
  npal /= del;
  npr /= del;
  era();
  long long cpal = 0, cprv = 0;
  long long cislo = 1;
  long long maxi = 0;
  while (cislo < up) {
    if (cpal * npal >= cprv * npr) maxi = cislo;
    if (jepal(cislo)) cpal++;
    if (vyh[cislo] == false) cprv++;
    cislo++;
  }
  cout << maxi - 1 << endl;
  return 0;
}
