#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n;
    long long m;
    cin>>n>>m;
    string k;
    cin>>k;
    long long x;
    long long y;
    vector<long long>listai;
    for (long long j=0;j<m;j++){
        cin>>x>>y;
        listai={};
        for (long long l=x;l<=y;l++){
            char c=k[l-1];
            if (c=='6'){
                listai.push_back(l);
            }
        }
        long long brs=y-x+1-listai.size();
        if (y==x+1 || y==x){
            cout<<0<<endl;
        }
        else{
            long long rez=0;
            for (long long i=0;i<listai.size();i++){
                if (listai[i]==1){
                    rez+=brs;
                }
                else if (i!=listai[listai.size()-1] || listai[listai.size()-1]!=y-x+1){
                    brs-=listai[i]-listai[i-1]-1;
                    rez+=brs;
                }
            }
            cout<<rez<<endl;
        }
    }
    return 0;
}