from bisect import bisect_left as bl n,q=map(int,input().split()) A=list(map(int,input().split())) S=[] for i in range(n): if A[i]==1: S.append(i) X=[0] for x in A: X.append(X[-1]+x//9) for _ in range(q): l,r=map(int,input().split()) l-=1 t=bl(S,r) u=bl(S,l) ans=X[r]-X[l] for i in range(u,t): ans+=min(r-l,r-1-S[i]) print(ans)