#include <bits/stdc++.h>
using namespace std;
int main() {
  int num;
  int n[100] = {0};
  while (cin >> num) {
    if (num == 0) break;
    for (int i = 0; i < num; ++i) {
      cin >> n[i];
    }
    int count = 0;
    for (int i = 0; i < num; ++i) {
      for (int j = i + 1; j < num; ++j) {
        if (n[i] > n[j]) {
          int tmp = n[i];
          n[i] = n[j];
          n[j] = tmp;
          ++count;
        }
      }
    }
    cout << count << "\n";
  }
  return 0;
}
