from bisect import * H,Q=map(int,input().split()) A=list(map(int,input().split())) L=sorted(list(set(A))) for i in range(Q): x,y=map(int,input().split()) if A[x-1] <= A[y-1]: print(0) continue print(((bisect(L,A[x-1])-bisect(L,A[y-1])-1)))