import scala.math._ object Main { def isPrime(n: Int): Boolean = { if (n <= 1) return false if (n == 2) return true if (n % 2 == 0) return false var p = 3 while (p*p <= n) { if (n % p == 0) return false p += 2 } return true } def main(args: Array[String]) { val sc = new java.util.Scanner(System.in) val n = sc.nextInt val ans = (max(4, n-100) to n+100).filter(!isPrime(_)).head println(ans) } }