#include <bits/stdc++.h>
int swap(int* a, int* b) {
  int t = *a;
  *a = *b;
  *b = t;
  return 1;
}
int main(void) {
  int n, a[100], i, j, c;
  for (;;) {
    scanf("%d", &n);
    if (!n) break;
    for (i = 0; i < n; i++) scanf("%d", a + i);
    for (i = n - 1; i; i--)
      for (j = 0; j < i; j++)
        if (a[j] > a[j + 1]) c += swap(a + j, a + j + 1);
    printf("%d\n", c);
  }
  return 0;
}
