import sys input = sys.stdin.readline sys.setrecursionlimit(10**8) from collections import defaultdict N, Q = map(int, input().split()) A = list(map(int, input().split())) querys = [list(map(int, input().split())) for _ in range(Q)] a = list(set(A)) a.sort() info = defaultdict(int) for n, e in enumerate(a): info[e] = n + 1 # ゼッケンから順位 rank = defaultdict(int) for i, a in enumerate(A): rank[i + 1] = info[a] cnt = defaultdict(int) for a in A: cnt[a] += 1 s = [0] for e in sorted(list(set(A))): s.append(s[-1] + cnt[e]) for x, y in querys: rx, ry = rank[x], rank[y] print(max(0, s[-ry - 1] - s[-rx]))