include<iostream>
#include<cstdio>
using namespace std;

int main(){
  int n,i,j,k,c,a[1000000];

  while(cin>>n&&n!=0){
    for(i=0;i<n;i++){
      cin>>a[i];
    }
    
    for(k=0,i=0;i<n-1;i++){
      for(j=i;j<n;j++){
	if(a[i]>a[j]){
	  c=a[i];
	  a[i]=a[j];
	  a[j]=c;
	  k++;
	} 
      }
    }
    cout<<k<<endl;
  }
return 0;
}