n,Q=map(int,input().split()) A=list(map(int,input().split())) for i in range(n): A[i]=[A[i],i+1] A.sort() P={} for i in range(n): P[A[i][-1]]=i for i in range(Q): a,b=map(int,input().split()) print(max(0,P[a]-P[b]-1))