#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, dx[101], comp, cnt;
  while (1) {
    cin >> n;
    if (n == 0) break;
    for (int i = 0; i < n; i++) {
      cin >> dx[i];
    }
    comp = n;
    cnt = 0;
    while (comp != 1) {
      for (int i = 0; i < comp; i++) {
        if (dx[i] > dx[i + 1]) {
          swap(dx[i], dx[i + 1]);
          cnt++;
        }
      }
      comp--;
    }
    cout << cnt << endl;
  }
  return 0;
}
