#include<stdio.h>
 
int main(){
	int a, b[100], i, c, count = 0, j;
	while(scanf("%d", &a) != 0){
		if(a == 0) break;
		for(i = 0; i < a; i++) scanf("%d", &b[i]);
		for(j = a - 1; j >= 1; j--){
			for(i = 0; i < j; i++){
				if(b[i + 1] < b[i]){
						c = b[i];
						b[i] = b[i + 1];
						b[i + 1] = c;
						count++;
				}
			}
		}
		printf("%d\n", count);
		count = 0;
	}
	return 0;
}