#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define ff first
#define ss second
#define pb push_back

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n, q, x, l, r;
    cin >> n >> q;
    vector<int> v(n+1), pref(n+1), suf(n+1), c;
    pref[0] = 0;
    for (int i=1; i<=n; i++) {
        cin >> v[i];
        pref[i] = pref[i-1] + (v[i] == 1);
    }
    suf[n] = (v[n] == 1);
    for (int i=n-1; i>0; i--) {
        suf[i] = suf[i+1] + (v[i] == 1);
    }
    ll two, mx;
    while (q--) {
        cin >> x >> l >> r;
        mx = -1;
        two = (1ll << (r-l+1));
        for (ll msk = 0; msk<two; msk++) {
            c = v;
            for (int i=0; i<(r-l+1); i++) {
                if ((msk >> i)%2 == 0) {
                    c[i] = 0;
                }
            }
            int cnt1=0, cnt2=0;
            bool f = true;
            for (int i=1; i<=n; i++) {
                cnt1 += (c[i] == 1);
                cnt2 += (c[i] == -1);
                if (cnt1 < cnt2) {
                    f = false;
                    break;
                }
            }
            if (f) {
                mx = max(mx, n-(ll)__builtin_popcount(msk));
                //cout << __builtin_popcount(msk) << " " << msk << "??\n";
            }
        }
        cout << mx << '\n';
    }
}