n, q = map(int, input().split())
A = list(map(int, input().split()))
for i in range(q):
    B = list(map(int, input().split()))
    if B[0] == 2:
        print(B[2] - B[1] + 1 - (A[B[1] - 1] == -1) - (A[B[2] - 1] == -1))