N,Q = list(map(int,input().split())) A = list(map(int,input().split())) one = [] for i in range(N): if(A[i] == 1):one.append(i) nine = [int(A[i] == 9) for i in range(N)] S = [0] for i in range(N): S.append(S[-1] + nine[i]) for _ in range(Q): l,r = list(map(int,input().split())) l -= 1;r -= 1 ans = S[r+1] - S[l] for i in one: if not (l <= i < r):continue ans += r-i print(ans)