N, Q=map(int, input().split()) A=list(map(int, input().split())) B=A[:] B.sort() import bisect for _ in range(Q): x, y=map(int, input().split()) rightIND=bisect.bisect_left(B, A[x-1]) leftIND=bisect.bisect_right(B, A[y-1]) print(max(0, rightIND-leftIND))