while 1:
    n = input(); ans = 0;
    if n==0: break
    s = [input() for i in range(n)]
    for i in range(n):
        for j in range(n-i-1):
            if s[j+1]<s[j]:
                s[j],s[j+1]=s[j+1],s[j]
                ans += 1
    print ans