n, q = map(int, input().split()) a = tuple(map(int, input().split())) for i in range(q): x, y = map(int, input().split()) Cx, Cy = a[x - 1], a[y - 1] count = 0 for i in a: if Cy < i < Cx: count += 1 print(count)