#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
int main(){
	int n,k, ind[100000];
	ind[0] = 1;
	freopen("knjige.in", "r", stdin);
	freopen("knjige.out", "w", stdout);
	scanf("%d%d", &n, &k);
	map<int, int> s;
	int v;
	scanf("%d", &v);
	s[v] = 1;
	for(int i = 1; i < n; i++) {
        scanf("%d", &v);
		if(s[v] != 1) {
            ind[i] = ind[i-1] + 1;
            s[v] = 1;
        }
		else ind[i] = ind[i-1];
	}
	
	//for(int i = 0; i < n; i++) cout << "IND:" << ind[i] << endl;
	for(int i = 0; i < k; i++){
		int b,e;
		scanf("%d%d", &b, &e);
		b--; e--;
		printf("%d\n", ind[e] - ind[b] + 1);
	}
	fclose(stdin); fclose(stdout);
	system("PAUSE");
}
