program f174

implicit none
integer :: i, j, k, l, r, n, q, z, w
integer, allocatable :: a(:), c(:)

read *, n, q
allocate(a(1:n))
allocate(c(1:n))

a(:) = 0
w = 0

read *, c(:)

do i = 1, q
 
 !if(w > 0) then
 w = 0
 a(:) = 0
 !end if
 
 read *, l, r
 do j = l, r
   a(c(j)) = a(c(j)) + 1
 end do
 
! print '(10(I2))', a(:)
 
 do k = 1, n
  if(a(k) > 0) then
   w = w + 1
  end if
 end do
 
print *, w

end do


end program f174