function main(input) {
  var primes = [2, 3]
  if (input == 2 || input == 3) {
    return input;
  }

  var base = 6
  while (true) {
    var root = Math.ceil(Math.sqrt(base))
    var tests = primes.filter(p => p <= root)

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

    if (tests.every(p => elder % p != 0)) {
      primes.push(elder);
      if (input <= elder) {
        return console.log(elder);
      }
    }
    if (tests.every(p => younger % p != 0)) {
      primes.push(younger);
      if (input <= younger) {
        return console.log(younger);
      }
    }
    base = base + 6;
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

