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
        m=0
        read(*,*)a,b
        do j=a,b
            c=y(j)
            
            if(x(c)==0)then
                m=m+1
                x(c)=1
            end if
        end do
        write(*,*)m
    end do
  
    stop
end program sample
  

