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