N,Q=map(int,input().split()) A=list(map(int,input().split())) from collections import defaultdict D=defaultdict(list) for i,a in enumerate(A,1): D[a].append(i) D=sorted(D.items()) P={} i=0 for L in D: i+=len(L[1]) for p in L[1]: P[p]=i for _ in range(Q): x,y=map(int,input().split()) if P[x]-P[y]-1>0:print(P[x]-P[y]-1) else:print(0)