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 for i in range(n): ls[tmp[i][1]] = i for _ in range(q): x, y = map(lambda x: int(x)-1, input().split()) print(max(0, ls[y]-ls[x]-1))