from sys import stdin n, *p = map(int, stdin.read().split()) ans = 0 ichi = [0 for i in range(n)] for i in range(n): for j in range(n): ichi[p[j]-1] = j for j in range(i,p[i]-1): ans += 1 p[ichi[j]], p[ichi[j+1]] = p[ichi[j+1]], p[ichi[j]] print("{}".format(ans))