#include <iostream>
#include <cstring>
#include <cstdio>

const int maxA = 1005;
const int maxK = 1005;

using namespace std;


int cap[maxA][maxK];
int lastCap[maxA];
bool exist[maxA];
int n, k, lbl;

FILE *fin = fopen("knjige.in", "r");
FILE *fout = fopen("knjige.out", "w");

int ccap(int tmp, int i)
{
    if (i == 0)
        return 0;
    if (cap[tmp][i] != 0)
        return cap[tmp][i];
    return ccap(tmp, i-1);
}

int solve(int p, int q)
{
    int sum = 0;
    for (int i = 1; i <= lbl; i++) 
        if ( exist[i] )
            if (ccap(i, q) > ccap(i, p-1))
                sum++;
    return sum;
}

int main () 
{
    memset(cap, 0, sizeof(cap));
    memset(exist, 0, sizeof(exist));
    memset(lastCap, 0, sizeof(lastCap));
    
    fscanf(fin, "%d %d", &n, &k);
    for (int i = 1; i <= n; i++) 
    {
        int tmp;
        fscanf(fin, "%d", &tmp);
        if (tmp > lbl) 
            lbl = tmp;
        exist[tmp] = true;
        cap[tmp][i] = lastCap[tmp] + 1;
        lastCap[tmp] = cap[tmp][i];
    } // O(N)
    
    for (int i = 0; i < k; i++)
    {
        int p, q;
        fscanf(fin, "%d %d", &p, &q);
    //    cout << solve(p, q) << endl; // O(maxA * k)
        fprintf(fout, "%d\n", solve(p, q));
    }
    
    fclose(fin);
    fclose(fout);

 //   system("PAUSE");
    return 0;    
}  
