#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
#define CR(t, x) const t &x
#define CLR(x) memset(x, 0, sizeof(x))
using namespace std;
typedef long long ll;
const int N = 1e5 + 50;
int n, a[N], b[N], idx, rt[N];
struct node
{
    int ch[2], sz;
} T[N * 20];
void insert(int y, int &x, int l, int r, int p)
{
    T[x = ++idx] = T[y];
    T[x].sz++;
    if (l == r - 1) return;
    int m = (l + r) >> 1;
    p < m ?
        insert(T[y].ch[0], T[x].ch[0], l, m, p) :
        insert(T[y].ch[1], T[x].ch[1], m, r, p);
}
int query(int nl, int nr, int l, int r, int k)
{
    if (l == r - 1) return l;
    int delta = T[T[nr].ch[0]].sz - T[T[nl].ch[0]].sz, m = (l + r) >> 1;
    return delta >= k ?
               query(T[nl].ch[0], T[nr].ch[0], l, m, k) :
               query(T[nl].ch[1], T[nr].ch[1], m, r, k - delta);
}
int main()
{
    for (int n, q; ~scanf("%d%d", &n, &q);)
    {
        CLR(a), CLR(b), CLR(rt), CLR(T), idx = 0;
        for (int i = 1; i <= n; i++) scanf("%d", a + i);
        memcpy(b, a + 1, n << 2);
        std::sort(b, b + n);
        int m = int(std::unique(b, b + n) - b);
        for (int i = 1; i <= n; i++)
            a[i] = int(std::lower_bound(b, b + m, a[i]) - b);
        for (int i = 1; i <= n; i++) insert(rt[i - 1], rt[i], 0, m, a[i]);
        while (q--)
        {
            int l, r;
            ll ans = -1;
            scanf("%d%d", &l, &r);
            if (r - l >= 2)
            {
                ll m1 = b[query(rt[l - 1], rt[r], 0, m, r - l + 1)];
                ll m2 = b[query(rt[l - 1], rt[r], 0, m, r - l)];
                ll m3 = b[query(rt[l - 1], rt[r], 0, m, r - l - 1)];
                for (int rk = 2; m1 >= m2 + m3 && rk < r - l; rk++)
                {
                    m1 = m2, m2 = m3;
                    m3 = b[query(rt[l - 1], rt[r], 0, m, r - l - rk)];
                }
                if (m3 + m2 > m1)
                    ans = m1 + m2 + m3;
            }
            printf("%lld\n", ans);
        }
    }
    return 0;
}