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