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