#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int n, a[102];

int solve() {
  rep (i,n) cin >> a[i];
  //rep (i,n) printf("%2d", a[i]); puts("");

  int ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = 0; j < n - (i+1); ++j) {
      if (a[j] > a[j+1]) { swap(a[j], a[j+1]); ans++; }
    }
  }
  //rep (i,n) printf("%2d", a[i]); puts("");
  return ans;
}

int main() {
  while (cin >> n, n) cout << solve() << endl;
  return 0;
}