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={} d=[0 for i in range(a)] for i in range(len(z)): p[z[i]]=i for i in range(a): w[p[x[i]]].add(i) d[i]=p[x[i]] 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))