program nextPrime
    implicit none
    integer(16):: x

    read*, x
    do while(.true.)
        call judge_prime(x)
        x = x + 1
    end do

contains
    subroutine judge_prime(x)
        integer(16):: x, i

        do i=2,int(sqrt(real(x)))
            if (mod(x,i) == 0) then
                return
            endif
        end do
        print*, x
        stop
    end subroutine


end program nextPrime