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