from bisect import bisect,bisect_left N,Q=map(int,input().split()) A=list(map(int,input().split())) SA=sorted(A) for tests in range(Q): x,y=map(int,input().split()) p=A[x-1] q=A[y-1] if p<=q: print(0) continue x=bisect(SA,q) y=bisect_left(SA,p) print(y-x)