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