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