import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		int a[];
		int count;

		while (true) {
			n = sc.nextInt();
			if (n == 0) {
				break;
			}

			a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
			}
			count = 0;
			for (int i = 0; i < n - 1; i++) {
				for (int j = 0; j < n - i - 1; j++) {
					if (a[j + 1] < a[j]) {
						int swap = a[j];
						a[j] = a[j + 1];
						a[j + 1] = swap;
						count++;
					}
				}
			}
			System.out.println(count);
		}
	}
}