n, q = map(int, input().split()) a = list(map(int, input().split())) tmp = [[a[i], i] for i in range(n)] tmp.sort(reverse = True) ls = [0] * n cnt = 0 for i in range(n): ls[tmp[i][1]] = cnt if i < n - 1 and tmp[i][0] != tmp[i+1][0]: cnt += 1 for _ in range(q): x, y = map(lambda x: int(x)-1, input().split()) print(max(0, ls[y]-ls[x]-1))