from bisect import bisect_left, bisect_right n, q = map(int, input().split()) a = list(map(int, input().split())) b = sorted(a) for _ in range(q): x, y = map(int, input().split()) x -= 1 y -= 1 ax = a[x] ay = a[y] r = bisect_left(b, ax) l = bisect_right(b, ay) print(max(0, r-l))