n, q = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
q.times do
  l, r = gets.split.map(&:to_i)
  i = (0..n-1).bsearch {|i| l <= a[i] } || n
  j = (0..n-1).bsearch {|j| r <  a[j] } || n
  p j - i
end
