N,Q=map(int,input().split()) A=list(map(int,input().split())) A=[(A[i],i) for i in range(N)] A.sort() X=[0]*N for i in range(N): X[A[i][1]]=i for tests in range(Q): x,y=map(int,input().split()) x-=1 y-=1 print(max(0,X[x]-X[y]-1))