import bisect n, q = map(int, input().split()) A = list(map(int, input().split())) B = sorted(A) for i in range(q): x, y = map(int, input().split()) x -= 1 y -= 1 l = bisect.bisect_right(B, A[y]) r = bisect.bisect_left(B, A[x]) if r - l <= 0: print(0) else: print(r - l)