      module primeMod
        implicit none
        
        contains
        function isPrime( x ) result( flag )
          implicit none
          integer(16),intent(in) :: x
          logical :: flag
          integer(16) :: n,i
          
          flag = .false.
          if(x==1) return
          if(x==2)then
            flag = .true.
            return
          end if
          
          n = int( sqrt(real(x))) + 1
          
          if( mod(x,2)==0 ) return
          do i = 3,n,2
            if( mod(x,i)==0 )then
              RETURN
            end if
          end do
          
          flag = .true.
        end function
      end module
      
      PROGRAM piyo
      use primeMod
      IMPLICIT NONE
      integer(16) :: x
      integer(16) :: counter
      
      read*,x
      counter = x
      do while( .true. )
        if( isPrime(counter) ) exit
        counter = counter + 1
      end do
      
      print*,counter
      
      
      
      END PROGRAM