n = int(input())
def isPrime(n):
    if n % 2 == 0:
        return n == 2
    d = 3
    while d * d <= n and n % d != 0:
        d += 2
    return d * d > n
for i in range(n, 2, -1):
    if isPrime(i):
        print(i)
        break
