#include <bits/stdc++.h>

#define int long long

using namespace std;

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

const ll inf = 1e18;
const ll mod = 2320;


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

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

        vector<int> d;
        for (int i = l; i <= r; i++) {
            d.push_back(v[i - 1]);
        }

        sort(d.begin(), d.end());
        int pos = d.size() / 2;
        cout << d[pos] << '\n';
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //    freopen(".in", "r", stdin);
    //freopen("output.out", "w", stdout);
    ll t = 1;
//    cin >> t;

    while (t--) {
        go();
    }
}
