import java.util.*

fun main(args: Array<String>) {
    val a = readLine()!!.toInt()

    val prime = ArrayList<Int>()
    prime.add(2)

    var x = 3
    while (prime.last() < a) {
        if (isPrime(x, prime)) prime.add(x)
        x += 2
    }
    println(prime.last())
}

fun isPrime(a: Int, p: List<Int>): Boolean {
    return p.takeWhile { it * it <= a }.all { a % it != 0}
}