n, q = map(int, input().split()) a = tuple(map(int, input().split())) indexs = dict() for (i, a_s) in enumerate(a): indexs[i + 1] = a_s def keys(a): global indexs return indexs[a] indexs = sorted(indexs, key=keys) for i in range(q): x, y = map(int, input().split()) print(-min(0, indexs.index(y) - indexs.index(x)) - 1)