#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  while (cin >> n, n) {
    vector<int> Vec(n);
    for (int i = 0; i < n; ++i) {
      cin >> Vec[i];
    }
    int count = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        if (Vec[i] > Vec[j]) {
          int temp = Vec[i];
          Vec[i] = Vec[j];
          Vec[j] = temp;
          count++;
        }
      }
    }
    cout << count << endl;
  }
}
int main() {
  solve();
  return (0);
}
