from collections import defaultdict import sys input = sys.stdin.readline N, Q = map(int, input().split()) A = list(map(int, input().split())) XY = [list(map(int, input().split())) for _ in range(Q)] B = defaultdict(int) for i, a in enumerate(A): B[a] += 1 P = list(B.keys()) P.sort(reverse=True) Z = dict() S = [0] for i in range(len(P)): p = P[i] Z[p] = i S.append(S[-1]+B[p]) for x, y in XY: x-=1 y-=1 xi = Z[A[x]] yi = Z[A[y]] if yi-1<0: ans = 0 else: ans = max(0, S[yi-1]-S[xi]) print(ans)