from bisect import bisect_right, bisect_left n, q = map(int, input().split()) print(n, q) a = list(map(int, input().split())) s = sorted(a) for _ in [0]*q: x, y = map(int, input().split()) l = bisect_right(s, a[y-1]) r = bisect_left(s, a[x-1]) if r <= l: print(0) else: print(r - l)