#include <bits/stdc++.h>
using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int main() {
  int n;
  while (scanf("%d", &n), n) {
    int so[128] = {0};
    for (int i = 0; i < n; i++) scanf("%d", &so[i]);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (so[i] > so[j]) {
          swap(so[i], so[j]);
          cnt++;
        }
      }
    }
    printf("%d\n", cnt);
  }
  return 0;
}
