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