function main(input) {
  console.log(nextPrimes(input, [2, 3]).pop())
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function nextPrimes(n, ps) {
  if (n == 1 || n == 2) {
    return [2]
  }

  var currentMax = ps[ps.length - 1]
  if (currentMax >= n) return ps;

  var search = true;
  var base = currentMax;
  while (search) {
    var elder = (Math.floor((base + 1) / 6) + 1) * 6 - 1
    var younger = (Math.floor((base + 1) / 6) + 1) * 6 + 1
    if (ps.every(p => elder % p != 0)) {
      search = false;
      ps.push(elder);
      if (elder > n) return ps;
    }
    if (ps.every(p => younger % p != 0)) {
      search = false;
      ps.push(younger);
    }
    base = base + 6;
  }

  return nextPrimes(n, ps)
}
