from collections import * n, q = map(int, input().split()) a = list(map(int, input().split())) b = [None] * n d = defaultdict(int) pl = defaultdict(int) for i in range(n): b[i] = (a[i], i) d[i] = a[i] pl[a[i]] += 1 b.sort() # ゼッケンiが全体で前から何番目か ans = [None] * n flg = False # print(pl) for i in range(n): di, p = b[i] # print(di, p) if i == 0: ans[p] = 0 former = p else: if d[former] == di: ans[p] = ans[former] flg = True else: if not flg: ans[p] = ans[former] + 1 else: ans[p] = ans[former] + pl[d[former]] flg = False former = p # print(ans) for _ in range(q): x, y = map(int, input().split()) x, y = x - 1, y - 1 if d[x] <= d[y]: print(0) else: print(ans[x] - ans[y]-1)