from bisect import bisect_left, bisect_right N, Q = map(int, input().split()) A = list(map(int, input().split())) d = {} for i, a in enumerate(A): d[i] = a ss = sorted(A) for _ in range(Q): x, y = map(lambda x: int(x)-1, input().split()) # x が y に追いつくには if d[x] <= d[y]: print(0) continue # d[y] < s < d[x] の個数 p = bisect_left(ss, d[y]+1) q = bisect_right(ss, d[x]-1) print(q - p)