N,Q=map(int,input().split()) A=list(map(int,input().split())) A_idx=[i for i in range(N)] A_idx.sort(key=lambda x:A[x]) x,y=[],[] for _ in range(Q): a,b=map(int,input().split()) print(max(A_idx[a-1]-A_idx[b-1]-1,0))