#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5e5 + 5;

int N, Q, A[MAXN], S[MAXN];

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> N >> Q;
    for(int i = 1; i <= N; i++) cin >> A[i];

    map<int, int> M;
    int mx = 0;
    for(int i = 1; i <= N; i++)
    {
        M[A[i]]++;
        mx = max(M[A[i]], mx);
        S[i] = mx;
    }
    while(Q--)
    {
        int l, r;
        cin >> l >> r;
        cout << S[r] - S[l - 1] << "\n";
    }

    return 0;
}