#include <stdio.h>

bool a[75][1000][1000];

int poc[10000];
int kraj[10000];
int autor[10000];
int broj[1000][1000];

int main()
{
    int n;
    int k;
    int m;
    int d1,d2;
    
    FILE *f;
    f=fopen("knjige.in","r");
    fscanf(f,"%d %d",&n, &k);
    
    
    for(int i=1;i<=n;i++)
    {
            fscanf(f,"%d",&m);
            autor[i]=m;
            a[m][i][i]=true;
            broj[i][i]=1;
    }
    
    for(int i=1;i<=k;i++)
    {
            fscanf(f,"%d %d",&d1, &d2);
            poc[i]=d1;
            kraj[i]=d2;
    }
    
    for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++)
    {
                 for(int l=1;l<=60;l++)
                 {
                         if(a[l][i][j-1])
                         a[l][i][j] = true;
                 }
                 
                 if(a[autor[j]][i][j]==false)
                 broj[i][j]=broj[i][j-1]+1;
                 else broj[i][j]=broj[i][j-1];
                 
                 
                 a[autor[j]][i][j]=true;
                 
                 
    }
    
    
    //fclose(f);
    f=fopen("knjige.out","w");
    
    for(int i=1;i<=k;i++)
    {
            fprintf(f,"%d\n",broj[poc[i]][kraj[i]]);
    }
    
    //fclose(f);
    //return 0;
    /*
    for(int i=1;i<=n;i++)
    fprintf(f,"%d",a[1][1][i]);
    */
    
}
