from bisect import bisect_left, bisect_right N, Q = map(int, input().split()) A = list(map(int, input().split())) sorted_A = sorted(A) for _ in range(Q): x, y = map(lambda x: int(x) - 1, input().split()) print(max(bisect_left(sorted_A, A[x]) - bisect_right(sorted_A, A[y]), 0))