#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int n,k,a[100001],b[100001],x,y;

int main()
{
    memset(b,0,sizeof(b));
    freopen("knjige.in","r",stdin);
    freopen("knjige.out","w",stdout);
    scanf("%d %d",&n, &k);
    a[0]=0;
    for(int i=1;i<=n;i++)
    {
       cin>>a[i];
       if(b[a[i]]==0)
       {
          b[a[i]]++;
          a[i]=a[i-1]+1;
       }
       else
          a[i]=a[i-1];
    }    
    for(int i=0;i<k;i++)
    {
       scanf("%d %d",&x, &y);
       printf("%d\n",a[y]-a[x-1]);
    }
    //system("PAUSE");
    return 0;
}
