n, q = map(int, input().split()) a = list(map(int, input().split())) a_idx = [] for idx, ai in enumerate(a): a_idx.append((ai, idx)) a_idx.sort(reverse=True) cnt = dict() for i in range(n): cnt[a_idx[i][1]] = i for _ in range(q): x, y = map(int, input().split()) x -= 1 y -= 1 if a[x] <= a[y]: print(0) else: print(max(0, cnt[y]-cnt[x]-1))