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