n, q = gets.chomp.split.map(&:to_i)
arr = gets.chomp.split.map(&:to_i)

h = Hash.new(0)
numbers = [0]
arr.each{|x|
    h[x] += 1
    numbers << x
}

arr2 = []
q.times{
    arr2 << gets.chomp.split.map(&:to_i)
    numbers << arr2.last[0]
    numbers << arr2.last[1]
}
numbers.uniq!
numbers.sort!

idx = {}
numbers.each_with_index{|x, i| idx[x] = i}

cum = Array.new(numbers.length, 0)
h.each{|k, v| cum[idx[k]] = v}
1.upto(cum.length - 1){|i| cum[i] += cum[i - 1]}

arr2.each{|l, r| puts cum[idx[r]] - cum[idx[l] - 1]}
