from bisect import * n,q=map(int,input().split()) a=list(map(int,input().split())) b=sorted(a) for i in range(q): x,y=map(int,input().split()) if a[x-1]<=a[y-1]: print(0) continue print(((bisect_left(b,a[x-1])-bisect(b,a[y-1]))))