#include <bits/stdc++.h>
int main(void) {
  int i, j, tmp, cnt, n, data[100];
  for (; scanf("%d", &n), n; printf("%d\n", cnt)) {
    for (i = n; i--; scanf("%d", data + i))
      ;
    cnt = 0;
    for (i = 0; i < n - 1; i++)
      for (j = n - 1; j-- > i;)
        if (data[j - 1] < data[j]) {
          tmp = data[j - 1];
          data[j - 1] = data[j];
          data[j] = tmp;
          cnt++;
        }
  }
  return 0;
}
