#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  while (cin >> n, n) {
    int a[n], sum = 0;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++)
      for (int j = 1; j < n; j++) {
        if (a[j - 1] > a[j]) {
          swap(a[i], a[j]);
          sum++;
        }
      }
    cout << sum << endl;
  }
}
