#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

int brc(int* a,int* c,int x, int y, int k)
{   int br=0;
    for (int i=x;i<=y;i++)
        {
             if (c[ a[i] ] != k) {
                                  c[ a[i] ]=k;
                                  br++;
                                  }
        }
    return br;
}
int main(int argc, char *argv[])
{
    ifstream in("knjige.in");
            if (!in) return -1;
    
    int n; 
    int k;
    in>>n>>k;
    
    int* a = new int [n];
    int* c = new int [n];
    
    for (int i=0;i<n;i++)
        {
             in>>a[i];
             c[i]=0;        
        }

    ofstream out("knjige.out");
    int x,y;
    for (int i=1;i<=k;i++)
    {
        in>>x>>y;
        x--;
        y--;
        out<<brc(a,c,x,y,i)<<endl;
    }
    
    //system("PAUSE");
    return EXIT_SUCCESS;
}
