def switch(list,x):
    y=list.pop(list.index(x))
    list.insert(0,y)
    return list

N=int(input())
list=list(map,(int,input().split()))
cnt=0

#print(list)

for i in range(N):
    #print(list[-1:],N-i)
    if list[-1:]==N-i:
        continue
    else:
        index=list.index(N-i)
        new_list=list[index+1:]
        for j in new_list:
            #print("new",new_list)
            list=switch(list,max(new_list))
            new_list.remove(max(new_list))
            cnt+=1
            #print(cnt,list)
        list.remove(N-i)
        #print(list)

print(cnt)