#include <bits/stdc++.h>
void swap(int *x, int *y) {
  int m = *x;
  *x = *y;
  *y = m;
}
int main() {
  int a[200], n, j, i;
  while (scanf("%d", &n), n) {
    j = 0;
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    for (i = 0; i < n - 1; i++)
      if (a[i] > a[i + 1]) {
        swap(&a[i], &a[i + 1]);
        j++;
      }
    printf("%d\n", j);
  }
  return 0;
}
