program ABC149C
    implicit none
    integer(8)::X,i,j
    integer(8)::div_max=int(sqrt(real(10003)))+1
    integer(8),dimension(100003)::P
    
    read(5,*)X

    P=1
    P(1)=0

    do i=4,100003
        if(mod(i,2)==0.or.mod(i,3)==0)then
            P(i)=0
        end if
    end do

    do i=5,div_max
        if(P(i)/=0)then
            do j=i+1,100003
                if(P(j)/=0)then
                    if(mod(j,i)==0)then
                        P(j)=0
                    end if
                end if
            end do
        end if
    end do

    do i=X,100003
        if(P(i)==1)then
            print'(i0)',i
            exit
        end if
    end do

end program ABC149C