n,q = map(int,input().split()) als = map(int,input().split()) for i in range(q): x,y = map(int,input().split()) if x <= y: print(0) else: c = 0 for j in range(n): if y < j < x: c += 1 print(c)