#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n, q;
vector<ll> a;
bool stepen(ll x){
    bitset<15> b(x);
    ll ans=0;
    for (ll i=0;i<15;i++){
        if (b[i]==1) ans++;
        if (ans>1) return false;
    }
    return true;
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> q;
    a.resize(n+2);
    for (ll i=0;i<n;i++){
        cin >> a[i];
    }
    while (q--){
        ll l, r; cin >> l >> r;
        map<ll, ll> m;
        ll ans=0;
        for (ll i=l-1;i<r;i++){
            m[a[i]]++;
            ans=max(ans, m[a[i]]);
        }
        cout << ans << '\n';
    }
    /*for (ll i=0;i<n;i++) cin >> a[i];
    while (q--){
        ll l, r; cin >> l >> r;
        set<ll> s;
        l--; r--;
        map<ll, ll> m;
        for (ll i=l;i<=r;i++){
            s.insert(a[i]);
            m[a[i]]++;
        }
        if (s.size()==1) {cout << r-l+1 << '\n'; continue;}
        ll ans=1;
        for (ll i:s){
            for (ll j:s){
                cout << i << " " << m[i] << " " << j << " " << m[j] << '\n';
                if (i==j) {ans=max(ans, m[i]); continue;}
                if (((i&j)>(i^j))) ans=max(ans, (m[i]+m[j]));
            }
        }
        cout << ans << '\n';
    }*/
    return 0;
}