from bisect import bisect_left as bs 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()) print(max(0, bs(B, A[x - 1]) - bs(B, A[y - 1] + 1)))