import random

def miller_rabin(n, k):
    if n == 2 or n == 3:
        return True
    if n <= 1 or n % 2 == 0:
        return False
    d = n - 1
    s = 0
    while d % 2 == 0:
        d //= 2
        s += 1
    for _ in range(k):
        a = random.randint(2, n - 2)
        x = pow(a, d, n)
        if x == 1 or x == n - 1:
            continue
        for _ in range(s - 1):
            x = pow(x, 2, n)
            if x == n - 1:
                break
        else:
            return False
    return True

def smallest_prime(N):
    if N <= 2:
        return 2
    k = 30 # number of iterations for Miller-Rabin test
    while True:
        if miller_rabin(N, k):
            return N
        N += 1

N = int(input())
print(smallest_prime(N))