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