n, q = map(int, input().split()) a = list(map(int, input().split())) b = sorted(a, reverse=True) for i in range(q): x, y = map(int, input().split()) if b.index(a[y - 1]) - b.index(a[x - 1]) > 0: print(b.index(a[y - 1]) - b.index(a[x - 1]) - 1) else: print(0)