#include <bits/stdc++.h>

using namespace std;


void sve_mogucnosti(vector<vector<bool>>& mogucnosti, vector<bool>& stek, int i) {
    if (i == stek.size()) {
        mogucnosti.push_back(stek);
        return;
    }
    stek[i] = true;
    sve_mogucnosti(mogucnosti, stek, i+1);
    stek[i] = false;
    sve_mogucnosti(mogucnosti, stek, i+1);
}

int broj67(string s, vector<bool>& upitnici) { // 1 - 6, 0 - 7
    int upitnik = 0;
    for (int i = 0; i<s.size(); i++) {
        if (s[i] == '?') {
            s[i] == (upitnici[upitnik++]) ? '6' : '7';
        }
    }
    vector<int> broj_sedmica(s.size() + 1, 0);
    broj_sedmica[0] = s[0] == '7';
    for (int i = 1; i<s.size(); i++) {
        broj_sedmica[i] = broj_sedmica[i-1] + s[i] == '7';
    }

    int res = 0;
    for (int i = 0; i<s.size(); i++) {
        res += (s[i] == '6') ? broj_sedmica[i + 1] : 0;
    }

    return res;
}

int najvise67(string s) {
    int cntq = 0;
    int res = 0;
    for (char c : s) cntq += c == '?';
    vector<vector<bool>> mogucnosti;
    vector<bool> stek(cntq);
    sve_mogucnosti(mogucnosti,  stek, 0);
    for (vector<bool>& row : mogucnosti) {
        res = max(res, broj67(s, row));
    }

    return res;



}

int main()
{
    ios_base::sync_with_stdio(false);
    int n, q;
    cin>>n>>q;
    string s;
    cin>>s;

    int l,r;
    for (int i = 0; i<q; i++) {
        cin>>l>>r;
        l--; r--;
        cout<<najvise67(s.substr(l, r-l+1))<<'\n';
    }

    

}