n, q = map(int, input().split()) A = list(map(int, input().split())) for i in range(q): B = [] x, y = map(int, input().split()) a = A[x-1] b = A[y-1] for j in range(len(A)): if b < A[j] < a: B.append(A[j]) print(len(B))