import sys input = sys.stdin.readline N,Q=map(int,input().split()) A=list(map(int,input().split())) SUM=[0] for a in A: SUM.append(SUM[-1]) if a==9: SUM[-1]+=1 ONE=[] for i in range(N): if A[i]==1: ONE.append(i) for tests in range(Q): l,r=map(int,input().split()) l-=1 ANS=SUM[r]-SUM[l] for x in ONE: if l<=x