def solve(n, q, a, xy): b = sorted(range(n), key=lambda x: a[x]) c = [0] * n for i, x in reversed(list(enumerate(b))): if i < n - 1 and a[b[i+1]] == a[x]: c[x] = c[b[i+1]] else: c[x] = i # print(c) for x, y in xy: print(max(c[x] - c[y] - 1, 0)) n, q = [int(x) for x in input().split()] a = [int(x) for x in input().split()] xy = [[int(x) - 1 for x in input().split()] for _ in range(q)] solve(n, q, a, xy)