#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<memory.h>
#include<algorithm>
#include<string.h>
#include<queue>

using namespace std;

    FILE *f, *g;

    vector<int> xx[100001];
    int autori[1001];//spisak njihovih brojeva
    int ainv[100001];//mesto u autori

    int a;//broj autora

    int n, k;

    bool exist(int a, int l, int d)//da li autor a postoji izmedju l i d
    {
        int m;

        int l1 = 0, d1 = xx[a].size()-1;
        int bestm = n+10;

        while(l1<=d1)
        {
                m  = (l1+d1)/2;
                if(xx[a][m]>=l) { d1 = m-1; if(m<bestm) bestm = m; }
                else l1 = m+1;
        }
        if(xx[a][bestm]<=d&&xx[a][bestm]>=l) return 1;
        return 0;
    }

    int main()
    {

        f = fopen("knjige.in","r");
        g = fopen("knjige.out","w");

        fscanf(f,"%d %d", &n, &k);

        int p;

        for(int i = 1; i <= n; i++)
        {
                fscanf(f,"%d",&p);
                xx[p].push_back(i);
                if(ainv[p]==0) { ainv[p] = a+1; a++; autori[a] = p; }
        }

       /* for(int i = 1; i <= a; i++)
        {
            for(int j = 0; j < xx[autori[i]].size(); j++)
            printf("%d ",xx[autori[i]][j]);
            printf("\n");
        }  */

        int L, D;

        //printf("tag");


// printf("%d", a);

        for(int i = 1; i <= k; i++)
        {
            fscanf(f,"%d%d",&L,&D);
            int resenje = 0;
            for(int j = 1; j <= a; j++) if(exist(autori[j], L, D)) { resenje++; }
            fprintf(g,"%d\n",resenje);
        }



    }
