N,Q=map(int, input().split()) A=list(map(int, input().split())) E={} for a in A: if a not in E: E[a]=0 E[a]+=1 B=sorted(list(set(A))) D={} for i in range(len(B)): D[B[i]]=i+1 F=[0] for b in B: F.append(F[-1]) F[-1]+=E[b] for i in range(Q): p,q=map(int, input().split()) p-=1;q-=1 p,q=F[D[A[p]]-1],F[D[A[q]]] print(max(0,p-q))