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

int main(void){

		int N, M;
		while(cin >> N, N){	
			int num[N], cnt = 0;
			fill_n(num, N, 0);
			for(int i = 0; i < N; i++){
				cin >> num[i];
			}
		        for(int i = N-1; i > 0; i--){
		            for(int j = 1; j <= i; j++){
		                if(num[j] < num[j-1]){
		                	int tmp;
		                	tmp = num[j];
		                	num[j] = num[j-1];
		                	num[j] = tmp;
		                    cnt++;
		                }
		            }
		        }
		    cout << cnt << endl;
		}
}