#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

const int inf = 1e9;
const ll mod = 1e9 + 7;
int m = 2321;

int dp[100001][2322];

void go(){
    int n, q;
    cin >> n >> q;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = dp[i - 1][j];
        }

        dp[i][v[i - 1]]++;
    }

    while (q--) {
        int l, r;
        cin >> l >> r;

        l--;
        int cnt = (r - l) / 2 + 1;
        for (int i = 0; i < m; i++) {
            cnt -= (dp[r][i] - dp[l][i]);
            if (cnt <= 0) {
                cout << i << '\n';
                break;
            }
        }
    }
}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
//    cin >> t;
    while (t--){
        go();
    }
}
