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