#include<cstdio>
int main(){
	int a[102],i,j,k;
	for(;scanf("%d",a),*a;printf("%d\n",k)){
		for(i=1;i<=n; i++)scanf("%d",*(a+i++));
		k=0;
		for(j=n;j>1;j--)
			for(i=2;i<=j;i++)
				if(a[i-1]>a[i])
					a[i-1]^=a[i],a[i]^a[i-1],a[i-1]^=a[i],k++;
	}
}