from collections import defaultdict import bisect N, Q = map(int, input().split()) A = list(map(int, input().split())) B = sorted(A) rank = defaultdict(int) for i in range(N): rank[i] = A[i] for i in range(Q): x, y = map(int, input().split()) posx = bisect.bisect_left(B, rank[x - 1]) posy = bisect.bisect_right(B, rank[y - 1]) print(max(posx - posy, 0))