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