#include <bits/stdc++.h>
using namespace std;
static const double PI = 6 * asin(0.5);
int a[110];
int main() {
  int n;
  while (cin >> n, n) {
    for (int i = 0; i < int(110); ++i) a[i] = 0;
    for (int i = 0; i < int(n); ++i) {
      cin >> a[i];
    }
    long long res = 0;
    for (int i = 0; i < int(n); ++i) {
      for (int j = i + 1; j < n; j++) {
        if (a[i] > a[j]) {
          int t;
          t = a[i];
          a[i] = a[j];
          a[j] = t;
          res++;
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}
