val memo = hashMapOf<Int, Long>()
fun generatePrime(index: Int): Long {
    if (index == 0) {
        return 2
    }
    if (index == 1) {
        return 3
    }
    memo[index]?.let {
        return it
    }
    val prev = generatePrime(index - 1)
    var next = prev + 2
    var i = 0
    var prime = 0L
    while (i < index - 1 && next > 2 * prime) {
        prime = generatePrime(++i)
        if (next % prime == 0L) {
            next += 2
            i = 1
        }
    }
    memo[index] = next
    return next
}

fun isPrime(candidate: Long): Boolean {
    var i = 0
    var prime = 0L
    while (candidate > 2 * prime) {
        prime = generatePrime(++i)
        if (candidate % prime == 0L) {
            return false
        }
    }
    return true
}

fun main(args: Array<String>) {
    val x = readLine()?.toInt() ?: return
    if (x == 2) {
        println(2L)
        return
    }
    var candidate = x + if (x % 2 == 0) {
        1L
    } else {
        0L
    }
    while (true) {
        val result = isPrime(candidate)
        if (result) {
            println(candidate)
            return
        }
        candidate += 2
    }
}

