#include <iostream>
#include <algorithm>
#include <queue>



using namespace std;

int main()
{
    ios_base::sync_with_stdio();
    cin.tie(NULL); cout.tie(NULL);

    long long n, m;
    cin >> n >> m;
    long long a[n];
    for (int i = 0; i<n; i++){
        cin >> a[i];
    }
    for (int i= 0; i<m; i++){
        int x, y;
        cin >> x >> y;
        int tipovi[n], brojaci[n];
        for (int j = 0; j<n; j++){
            tipovi[j]=0;
            brojaci[j]=0;
        }
        for (int j = x-1; j<y; j++){
            int k = a[j];
            int r=0;
            while (tipovi[r]!=k && tipovi[r]!=0){
                r++;
                //cout << tipovi[r] << " " << brojaci[r] << endl;
            }
            tipovi[r]=k;
            brojaci[r]--;
        }
        sort(brojaci, brojaci+n);
        cout << brojaci[0]*(-1) << endl;
    }

    return 0;
}