program main

  implicit none

  integer :: i, j, k, l, n
  integer, parameter :: limit = 1000000
  integer :: prime

  read(*,*) i
  n = 0
  do k = i, limit
    l = 0
    if ( mod( k, 2 ) == 0 .and. k /= 2 ) cycle

    do j = 2, int( sqrt( real( k ) ) )
      if( mod(k, j) == 0 ) then
        l = l + 1
      end  if
    end do

    if ( l == 0 ) then
      prime = k
      exit
    end  if

  end do

  print*, prime


end program main