# 標準入力された値を整数に変換する def INT(): return int(input()) # 標準入力された複数の値を整数に変換する def MI(): return map(int, input().split()) # 標準入力された複数の値を整数のリストに変換する def LI(): return list(map(int, input().split())) from bisect import bisect_left, bisect_right N, Q = MI() A = LI() As = sorted(A) for i in range(Q): x, y = MI() x -= 1 y -= 1 ans = max(bisect_left(As, A[x]) - bisect_right(As, A[y]), 0) print(ans)