program next_prime
  implicit none
  integer :: x, i, j
  logical :: p(100003) = .false.
  read(*,*) x
  p(1) = .true.
  do i = 1, x-1
    if (p(i)) cycle
    do j = i, 100003, i
      p(j) = .true.
    end do
  end do
  do i = x, 100003
    if (p(i)) cycle
    write(*,'(i0)') i
    stop
  end do
end program next_prime