m = int(eval(input()))

if m <= 2 :

  print('2')

else:

  n = 10**6

  primes = set(range(2, n+1))

  for i in range(2, int(n**0.5+1)):

      primes.difference_update(list(range(i*2, n+1, i)))

  primes=list(primes)



  for i in range(len(primes)-1):

    if primes[i] < m and m <= primes[i+1]:

      print((primes[i+1]))
m = int(eval(input()))

if m <= 2 :

  print('2')

else:

  n = 2*10**5

  primes = set(range(2, n+1))

  for i in range(2, int(n**0.5+1)):

      primes.difference_update(list(range(i*2, n+1, i)))

  primes=list(primes)



  for i in range(len(primes)-1):

    if primes[i] < m and m <= primes[i+1]:

      print((primes[i+1]))



m = int(eval(input()))
if m <= 2:
    print("2")
else:
    n = 10**6
    primes = set(range(2, n + 1))
    for i in range(2, int(n**0.5 + 1)):
        primes.difference_update(list(range(i * 2, n + 1, i)))
    primes = list(primes)
    for i in range(len(primes) - 1):
        if primes[i] < m and m <= primes[i + 1]:
            print((primes[i + 1]))

m = int(eval(input()))
if m <= 2:
    print("2")
else:
    n = 2 * 10**5
    primes = set(range(2, n + 1))
    for i in range(2, int(n**0.5 + 1)):
        primes.difference_update(list(range(i * 2, n + 1, i)))
    primes = list(primes)
    for i in range(len(primes) - 1):
        if primes[i] < m and m <= primes[i + 1]:
            print((primes[i + 1]))

-    n = 10**6 +    n = 2 * 10**5