while True:
    n=input()
    if n==0:break
    cnt=0
    L=[input() for i in range(n)]
    for j in range(n):
        for i in range(n-j-1):
            if L[i]>L[i+1]:
                L[i],L[i+1]=L[i+1],L[i]
                cnt+=1
    print cnt