N, Q = map(int, input().split()) A = list(map(int, input().split())) idx = {} current = min(A) cnt = 0 total = 0 for x in sorted(A) + [10**10]: cnt += 1 if x != current: idx[current] = [total, total+cnt] total += cnt cnt = 0 current = x queries = [list(map(lambda x: int(x)-1, input().split())) for _ in range(Q)] for x, y in queries: print(max(idx[A[x]][0] - idx[A[y]][1], 0))