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

function nextPrimes(n, ps) {
  var currentMax = ps[ps.length - 1]
  if (n <= currentMax) return ps;

  var base = (Math.floor((currentMax + 1) / 6) + 1)* 6;
  while (true) {
    var root = Math.floor(Math.sqrt(base))
    var tests = ps.filter(p => p < root)

    var elder = base - 1
    var younger = base + 1

    if (tests.every(p => elder % p != 0)) {
      ps.push(elder);
      if (n <= elder) return ps;
    }
    if (tests.every(p => younger % p != 0)) {
      ps.push(younger);
      if (n <= younger) return ps;
    }
    base = base + 6;
  }
}
