def solve(n, q, a, xy): b = sorted(range(n), key=lambda x: a[x]) c = [0] * n for i, x in enumerate(b): if i > 0 and a[b[i-1]] == a[x]: c[x] = c[b[i-1]] else: c[x] = i 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)