#include <bits/stdc++.h>
using namespace std;
const int INF = 100000000;
int main() {
  int n;
  while (cin >> n, n != 0) {
    int a[20];
    int c = 0;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n - 1 - i; j++) {
        if (a[j] > a[j + 1]) {
          int temp;
          temp = a[j];
          a[j] = a[j + 1];
          a[j + 1] = temp;
          c++;
        }
      }
    }
    cout << c << endl;
  }
  return 0;
}
