import bisect N,Q=map(int,input().split()) A=list(map(int,input().split())) sorted_A=sorted(A) for q in range(Q): x,y=map(int,input().split()) x-=1;y-=1 if A[y]>=A[x]: ans=0 else: ans=bisect.bisect_left(sorted_A,A[x])-bisect.bisect_right(sorted_A,A[y]) print(ans)