#include <bits/stdc++.h>
int main() {
  int a[102], i, j, k;
  for (; scanf("%d", a), *a; printf("%d\n", k)) {
    for (i = 1; i <= *a; i++) scanf("%d", *(a + i++));
    k = 0;
    for (j = *a; j > 1; j--)
      for (i = 2; i <= j; i++)
        if (a[i - 1] > a[i])
          a[i - 1] ^= a[i], a[i] ^ a[i - 1], a[i - 1] ^= a[i], k++;
  }
}
