from bisect import bisect_left, bisect_right N, Q = map(int, input().split()) A = list(map(int, input().split())) B = A[:] B.sort() # print(B) for _ in range(Q): xq, yq = map(int, input().split()) xq -= 1 yq -= 1 # print(A[xq], A[yq]) if A[xq] <= A[yq]: print(0) else: r = bisect_left(B, A[xq]) l = bisect_right(B, A[yq]) print(r - l)