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