import sys input = sys.stdin.readline N,Q = map(int,input().split()) A = list(map(int,input().split())) XY = [tuple(map(int,input().split())) for _ in range(Q)] from collections import Counter C = Counter(A) sc = sorted(C.items()) cums = [0] ks = [] for k,v in sc: cums.append(cums[-1] + v) ks.append(k) from bisect import bisect for x,y in XY: x,y = x-1,y-1 a = A[x] b = A[y] i = bisect(ks,a)-1 j = bisect(ks,b) print(max(0, cums[i] - cums[j]))