#include <bits/stdc++.h>
 #define endl "\n"

using namespace std;

using ll = long long;
const ll inf =1e12;
void solve()
{
    ll j,tren,broj,brojac;
    ll n,q,i,br,res=0 ,oduz1,oduz2,l,r=0;
    string s;
    cin >> n >> q;
    cin >> s;
    for(i=0;i<n;i++)
    {
        if(s[i]!='?')
        {
            r=1;
        }
    }
    if(r==0)
    {
        while(q--)
        {
            cin >> l >> r;
            res=r-l+1;
            cout << (res/2) * ((res+1)/2) << endl;
        }
    }
    while(q--)
    {
        cin >> l >> r;
        l--;
        r--;
        br=0;
        for(i=l;i<=r;i++)
        {
            if(s[i]=='?')
            {
                br++;
            }
        }
        res=0;
        for(j=0;j<=br;j++)
        {
            tren=0;
            broj=0;
            brojac=0;
            for(i=l;i<=r;i++)
            {
                if(s[i]=='7')
                {
                    tren+=broj;
                }
                else if(s[i]=='6')
                {
                    broj++;
                }
                else if(brojac==j)
                {
                    tren+=broj;
                }
                else
                {
                    broj++;
                    brojac++;
                }
            }
            res=max(res,tren);
        }
        cout << res << endl;
    }


}



int main()
{
    ios_base::sync_with_stdio(false);
   cin.tie(NULL);
    ll t=1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
}