program abc149_c
    implicit none
    integer(4) :: X, i
    read(*, *) X

    do i = X, 100003
        if( isPrime(i) .eqv. .true. ) then
            print *, i
            exit
        endif
    enddo


contains
    logical function isPrime(x) result(res)
        implicit none
        integer(4), intent(in) :: x
        integer(4) :: i, sqrtNum

        if( x < 2 ) then
            res = .false.
            return
        else if( x == 2 ) then
            res = .true.
            return
        else if( mod(x, 2) == 0 ) then
            res = .false.
            return
        endif

        sqrtNum = nint(SQRT(real(x))) + 1
        do i = 3, sqrtNum, 2
            if( mod(x, i) == 0 ) then
                res = .false.
                return
            endif
        enddo
 
        res = .true.
    end function isPrime
end program abc149_c