n = int(input())
houses = list(map(int, input().split()))
wires = 0
for plaque in range(1, n + 1):
index = houses.index(plaque)
sec_index = houses.index(plaque, index + 1)
distance = sec_index - index
wires += distance
else:
del plaque, index, sec_index, distance
print(wires)