from bisect import bisect_left n, q = map(int, input().split()) a = list(map(int, input().split())) b = list(sorted(a)) for _ in range(q): x, y = map(int, input().split()) x -= 1 y -= 1 # a[x]未満の個数 ans = bisect_left(b, a[x]) # a[y]以下の個数 ans -= bisect_left(b, a[y] + 1) print(max(0, ans))