#include <stdio.h>

long has_author[100000];
long books[100000];

int main(int argc, char *argv[])
{
	FILE *fin = fopen("knjige.in", "r");
	FILE *fout = fopen("knjige.out", "w");
	long n, K;
	fscanf(fin, "%d %d\n", &n, &K);
	for (long loop_n=0; loop_n<n; loop_n++) {
		fscanf(fin, "%d ", &books[loop_n]);
		has_author[books[loop_n]] = -1;
	}
	for (long loop_K=0; loop_K<K; loop_K++) {
		long int_start, int_end;
		fscanf(fin, "%d %d\n", &int_start, &int_end);
		int_start--;
		long sol=0;
		for (long loop_int=int_start; loop_int<int_end; loop_int++) {
			if (has_author[books[loop_int]] != loop_K) {
				has_author[books[loop_int]] = loop_K;
				sol++;
			}
		}
		fprintf(fout, "%d\n", sol);
	}
	fclose(fin);
	fclose(fout);
}
