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