a,b=map(int,input().split()) x=list(map(int,input().split())) z=sorted(list(set(x))) w=[set([]) for i in range(len(z))] p={} for i in range(len(z)): p[z[i]]=i for i in range(a): w[p[x[i]]].add(i) d=[0 for i in range(a)] for i in range(a): for j in range(len(w)): if i in w[j]: d[i]=j break for i in range(b): c=list(map(int,input().split())) c[0]-=1;c[1]-=1 print(max(d[c[0]]-d[c[1]]-1,0))