using System;
using System.Collections.Generic;
namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            int length = 0;
            List<int> input = new List<int>();
            Func<int, int, bool> Swap = new Func<int, int, bool>( (index1,index2) => {
                bool result = false;
                if(input.Count > index1 && input.Count > index2 && input[index1] < input[index2]) {
                    input[index1] = input[index1] - input[index2];
                    input[index2] = input[index2] + input[index1];
                    input[index1] = input[index2] - input[index1];
                    result = true;
                }
                return result;
            });
            while((length = int.Parse(Console.ReadLine())) != 0) {
                input.Clear();
                int count = 0;
                for(int i=0; i < length; ++i) {
                    input.Add(int.Parse(Console.ReadLine()));
                }
                for(int i=0; i < length; ++i) {
                    for(int l=i + 1; l < length; ++l) {
                        count += Swap(l, i) ? 1 : 0;
                    }
                }
                Console.WriteLine(count);
            }
        }
    }
}