'''input''' i1=lambda:int(s1()) i2=lambda:map(int,s2()) il=lambda:list(i2()) s1=lambda:input() s2=lambda:s1().split() sl=lambda:list(s2()) '''output''' yn=lambda b:print("Yes" if b else "No") '''createList''' cl=lambda x,d:[d for i in range(x)]# a=c2l(10,23,"x") '''code''' N,Q=i2() A=il() S = sorted(list(set(A))) ranking = {x:i+1 for i,x in enumerate(S)} z = [] for a in A: z.append(ranking[a]) print(z) for i in range(Q): n,m=i2() if z[n-1]-z[m-1]>0: if z[n-1]-z[m-1]==1: print(1) else: print(z[n-1]-z[m-1]-1) else: print(0)