#include<iostream>
using namespace std;
int main(){
	int n;
	while (cin >> n, n){
		int sort[100], hoge, cnt = 0;
		for (int i = 0; i < n; i++){
			cin >> sort[i];
		}
		for (int i = 0; i < n - 2; i++){
			for (int j = 0; j < n - 1 - i; j++){
				if (sort[j] > sort[j + 1]){
					hoge = sort[j];
					sort[j] = sort[j + 1];
					sort[j + 1] = hoge;
					cnt++;
				}
			}
		}
		cout << cnt << "\n";
	}
	return 0;
}