N=int(input()) P=list(map(int, input().split())) res=0 for i in range(N,0,-1): ind=P.index(i) res+=i-ind-1 P=P[:ind]+P[ind+1:] print(res)