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

int kaijyou(int x){
int b=1;
for(int i=1;i<x;i++){
b*=i;
}
return b;
}

int main(){
int n,t;
int ans;
double count;
while(cin>>n){
if(n==0)return 0;
int a[n];
t=0;
ans=0;
count=0;
for(int i=0;i<n;i++){
cin >> a[i];
}
for(int j=0;t==0;j++){
if(j+1==n){
j=0;
count+=1;
}
if(a[j]>a[j+1]){
swap(a[j],a[j+1]);
ans+=1;
}
if(count>kaijyou(n)){
cout << ans << endl;
t=1;
}
}
}

return 0;
}