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