using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication11 {
    class Program {
        static void Main(string[] args) {
            new Program().solve();
        }

        void solve() {
            while (true) {
                int num_length = int.Parse(Console.ReadLine());
                if (num_length == 0) {
                    return;
                }
                int[] input = new int[num_length];
                for (int i = 0; i < input.Length; i++) {
                    input[i] = int.Parse(Console.ReadLine());
                }

                int sorted = 0;
                int allsorted = 0;
                do {
                    sorted = 0;
                    for (int i = 0; i < input.Length - 1; i++) {
                        int tmp = input[i];
                        if (input[i] > input[i+1]) {
                            input[i] = input[i + 1];
                            sorted++;
                        } else break;
                        input[i + 1] = tmp;
                    }
                    allsorted += sorted;
                } while (sorted > 0);
                Console.WriteLine(allsorted);
            }
        }
    }
}