#include <iostream>

using namespace std;

int main()
{
    int n,q,br=0,n1;
    cin>>n;cin>>q;
    int l[q],r[q];
    char niz[n],niz1[100];
    for(int i=0;i<n;i++){
        cin>>niz[i];
    }
    for(int i=0;i<q;i++){
        br=0;
        cin>>l[i]>>r[i];
        n1 = r[i]-l[i]+1;
        for(int j=l[i]-1;j<r[i];j++){
            if(niz[j] == '6'){
                for(int m=j+1;m<r[i];m++){
                    if(niz[m]=='7')
                        br++;
                    else if(niz[m] == '6' && niz[m+1] == '7'){
                        br++;
                        m++;
                    }
                }
            }
        }
        cout<<br;
    }
}