#include <bits/stdc++.h>
int main() {
  int n, m, A[100], count = 0, taihi, i, j, k;
  while (1) {
    scanf("%d", &n);
    if (n == 0) break;
    for (i = 0; i < n; i++) {
      scanf("%d", &m);
      A[i] = m;
    }
    for (k = n; k > 0; k--) {
      for (j = 0; j < n; j++) {
        if (A[j] > A[j + 1]) {
          taihi = A[j];
          A[j] = A[j + 1];
          A[j + 1] = taihi;
          count += 1;
        }
        if (count == 0) break;
      }
    }
    printf("%d\n", count);
    count = 0;
  }
  return 0;
}
