n,q = map(int,input().split()) als = list(map(int,input().split())) for i in range(q): x,y = map(int,input().split()) if als[x-1] <= als[y-1]: print(0) else: c = 0 for j in als: if als[y-1] < j < als[x-1]: c += 1 print(c)