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