# セグ木 ビットOR
class SegmentTree
  # 配列（もしくは配列のサイズ）、初期値、function
  def initialize(n, unity, &func)
    raise ArgumentError if !n || !unity || !block_given?
    @size_r = 1
    @n = (n.is_a?(Array) ? n.size : n)
    while @size_r < @n
      @size_r <<= 2
    end
    @func = func
    # 初期値
    @unity = unity
    @data = Array.new(@size_r * 2, @unity)
    # 配列が渡された場合、初期値をセットして辺を張る
    if n.is_a?(Array)
      @n.times { |i| @data[i + @size_r] = n[i] }
      self.build()
    end
  end

  # 0-indexed
  def set(index, value)
    raise IndexError if index >= @n
    @data[index + @size_r] = value
  end

  # 辺を張る
  def build
    (@size_r - 1).downto(1) do |k|
      @data[k] = @func.call(@data[k * 2], @data[k * 2 + 1])
    end
  end

  # 0-indexed
  def update(index, value)
    raise IndexError if index >= @n
    index += @size_r
    @data[index] = value
    index >>= 1
    while index > 0
      @data[index] = @func.call(@data[index * 2], @data[index * 2 + 1])
      index >>= 1
    end
    true
  end

  # 0-indexed b を含まず
  def get(a, b)
    raise IndexError if a > @n || b > @n || a > b
    vleft = vright = @unity
    left = a + @size_r
    right = b + @size_r
    while (left < right)
      if left.odd?
        vleft = @func.call(vleft, @data[left])
        left += 1
      end
      if right.odd?
        right -= 1
        vright = @func.call(@data[right], vright)
      end
      left >>= 1
      right >>= 1
    end
    @func.call(vleft, vright)
  end

  def [](k)
    @data[@size_r + k]
  end
end

n, q = gets.split.map(&:to_i)
balls = gets.split.map(&:to_i)
str = '0' * n
queries = []
q.times { queries << gets.split.map(&:to_i) }
bit_balls = balls.map { |ball|
  copy = str.dup
  copy[n - ball] = '1'
  copy.to_i(2)
}
seg = SegmentTree.new(bit_balls, 0) { |x, y| x | y }
queries.each do |a, b|
  puts seg.get(a - 1, b).to_s(2).count("1")
end
