import typing import sys # sys.setrecursionlimit(100100) from collections import defaultdict input = lambda: sys.stdin.readline().strip() inf = 10**18 mod = 998244353 # import heapq def solve(): N, Q = map(int, input().split()) order = [-1 for _ in range(N)] same_order = [-1 for _ in range(N)] A_ = list(map(int, input().split())) A = [(A_[i], i) for i in range(N)] A.sort() for idx, (v, i) in enumerate(A): order[i] = idx sz = defaultdict(int) for i, x in enumerate(A_): same_order[i] = sz[x] sz[x] += 1 for _ in range(Q): x, y = map(lambda x: int(x)-1, input().split()) ans = order[x]-order[y]-1 ans -= same_order[x] ans -= sz[A_[y]]-same_order[y]-1 print(max(0, ans)) def main(): t = 1 for _ in range(t): solve() main()