#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, Q = get_ints
C = get_ints
X = []
Q.times do |i|
  X[i] = get_ints
end

xx = X.map.with_index { |(l, r), i| [l, r, i] }

xx.sort! do |x, y, _|
  if (x[1] <=> y[1]) == 0
    x[0] <=> y[0]
  else
    x[1] <=> y[1]
  end
end

array = []
hash = Hash.new { |h,k| h[k] = 0 }
x_index = 0
ans = []

C.each.with_index do |color, i|
  cur_index = hash[color]
  next_index = i + 1
  hash[color] = next_index
  if cur_index != 0
    array_index = array.bsearch_index { |a| a >= cur_index }
    array.delete_at(array_index)
  end
  array.push(next_index)

  while xx[x_index] != nil && xx[x_index][1] == next_index
    l, r, i = xx[x_index]
    index = array.bsearch_index { |a| a >= l }
    ans[i] = array.length - index
    x_index += 1
  end
end

ans.each do |a|
  puts a
end
