import bisect n, q = map(int,input().split()) A = [int(i)*-1 for i in input().split()] R = sorted(A) for i in range(q): x,y=map(int, input().split()) ans=bisect.bisect_right(R,A[x-1])-bisect.bisect_left(R,A[y-1]) if A[x-1] >= A[y-1]: print(0) else: print(-1*total)