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)] info = [] for i in range(N): info.append([A[i], i + 1]) allA = sorted(list(set(A))) cnt = defaultdict(int) for a in A: cnt[a] += 1 s = [0] for a in allA: s.append(s[-1] + cnt[a]) place = defaultdict(int) info.sort() for n, e in enumerate(info): place[e[-1]] = n + 1 for x, y in querys: p1, p2 = place[x], place[y] print(max(0, s[p1 - 1] - s[p2]))