#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {

    while(true){
        int n;
        cin >> n;
        if(n==0){
            break;
        }
        
        int array[100] = {0};
        for(int i=0;i<n;i++){
            cin >> array[i];
        }
        
        
        int count = 0;
        int i = 0;
        int j = n - 1;
        while(j>0){
            
            if(i == j){
                i = 0;
                j--;
            }
            else if(array[i] > array[i+1]){
                int t = array[i];
                array[i] = array[i+1];
                array[i+1] = t;
                i++;
                count++;
            }
            else{
                i++;
            }
            
        }
        
        cout << count << endl;
        
    }
    
    
    return 0;
}