#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <ctime>
using namespace std;
#define NAME "volleyball"
const int N = 2e5 + 10;
const int M = 2e5 + 10;
const int LOGN = 19;
int a[N];

int main() {
    //double start = clock();
    freopen(NAME ".in", "r", stdin);
    freopen(NAME ".out", "w", stdout);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);

    for (int i = 0; i < m; ++i) {
        int l, r;
        scanf("%d%d", &l, &r);
        --l;
        --r;
        int ans = 0;
        for (int s = l; s <= r; ++s) {
            int mx = 0;
            for (int t = s; t <= r; ++t) {
                mx = max(mx, a[t]);
                if (a[s] == a[t] && mx <= a[s])
                    ans = max(ans, t - s);
            }
        }
        printf("%d\n", ans);
    }
    //cerr <<(clock()-start)/CLOCKS_PER_SEC << endl;
    return 0;
}
