import sys input = sys.stdin.readline N, Q = map(int, input().split()) A = list(map(int, input().split())) XY = [list(map(int, input().split())) for _ in range(Q)] B = [] for i, a in enumerate(A): B.append((a, i)) B.sort(reverse=True) R = [0 for _ in range(N)] for i in range(N): _, j = B[i] R[j] = i for x, y in XY: x-=1 y-=1 ans = max(0, R[y]-R[x]-1) print(ans)