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 xx = bisect_left(B, A[x]) yy = bisect_right(B, A[y]) ans = max(0, xx - yy) print(ans)