program sample
    implicit none
  
    integer(8) :: i,j,m,n,k,a,b,c
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n,k
    allocate(x(n),y(n))
    read(*,*)y

    do i=1,k
        x(:)=0
        read(*,*)a,b
        do j=a,b
            c=y(j)
            x(c)=1
        end do
        write(*,*) sum(x)
    end do
  
    stop
end program sample
  

