n,q=map(int,input().split()) a=[*map(int,input().split())] dists=sorted(set(a)) dic=dict() for i in range(len(dists)): dic[dists[i]]=i for _ in range(q): x,y=map(int,input().split()) x-=1 y-=1 print(max(0,dic[a[x]]-dic[a[y]]-1))