#include <stdio.h>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int a[100000];
vector<int> autor[100000];
vector<int> autori;
vector<int> au;
int nadji (int j, int leva,int desna, int t)
{
    if (desna-leva<=1) 
    {
         if (autor[j][leva]>= t) return leva;
         else  if (autor[j][desna]>=t) return desna; else return 1000000;
    }
    else
    {
        int s=(leva+desna)/2;
        printf("%d",s);
        if (autor[j][s]<t) return nadji(j,s,desna,t);
        else return nadji(j,leva,s,t);
    }
}
int main ()
{
    int n,k;
    FILE *f=fopen("knjige.in","r");
    fscanf(f,"%d %d",&n,&k);
    for (int i=0;i<n;i++)
    {
        fscanf(f,"%d",&a[i]);
        autor[a[i]].push_back(i);
        autori.push_back(a[i]);
    }
    sort(autori.begin(),autori.end());
    for (int i=0;i<autori.size();i++)
    {
        //printf("%d \n",autori[i]);
        if (i==0) au.push_back(autori[i]);
        else if (autori[i]!=autori[i-1]) au.push_back(autori[i]);
    }
    for (int j=0;j<au.size();j++)
    {
        //printf("%d \n",au[j]);
         sort(autor[au[j]].begin(),autor[au[j]].end());
    }
    FILE *g=fopen("knjige.out","w");
    for (int i=0;i<k;i++)
    {
        int l,d,res=0;
        fscanf(f,"%d %d",&l,&d);
        l--;
        d--;
        for (int j=0;j<au.size();j++)
        {
            int pom=nadji(au[j],0,autor[au[j]].size()-1,l);
            if (pom<autor[au[j]].size()) if (autor[au[j]][pom]<=d) res++;
        }
        fprintf(g,"%d\n",res);
    }
    fclose(f);
    fclose(g);
}
