#include <bits/stdc++.h>
using namespace std;

const int N = 500100;
int n, q, c[N], l, r, qs[N], pos[N];
vector<pair<int, int>> ls[N];

int bit[N];
void add(int i, int d) {
  for (; i <= n; i += i & -i) {
    bit[i] += d;
  }
}
int prefix(int i) {
  int s = 0;
  for (; i > 0; i -= i & -i) {
    s += bit[i];
  }
  return s;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> c[i];
  }
  for (int i = 1; i <= q; ++i) {
    cin >> l >> r;
    ls[r].emplace_back(l, i);
  }
  for (int i = 1, s = 0; i <= n; ++i) {
    int& p = pos[c[i]];
    if (p) add(p, -1);
    else ++s;
    p = i;
    add(i, 1);
    for (auto [l, j] : ls[i]) {
      qs[j] = s - prefix(l - 1);
    }
  }
  for (int i = 1; i <= q; ++i) {
    cout << qs[i] << "\n";
  }
  return 0;
}
