#include <bits/stdc++.h>
int bubbleSort(int array[], int n);
int main() {
  int arraySize;
  int* insertedData;
  int changeLineFlag = 0;
  while (1) {
    scanf("%d", &arraySize);
    if (arraySize == 0) break;
    if (changeLineFlag == 0) {
      changeLineFlag++;
    } else {
      printf("\n");
    }
    insertedData = (int*)malloc(sizeof(int) * arraySize);
    for (int i = 0; i < arraySize; i++) scanf("%d", &insertedData[i]);
    int result = bubbleSort(insertedData, arraySize);
    printf("%d", result);
    free(insertedData);
  }
  return 0;
}
int bubbleSort(int array[], int n) {
  int counter = 0;
  int flag = 1;
  while (flag == 1) {
    flag = 0;
    for (int i = 0; i < n - 1; i++) {
      if (array[i] > array[i + 1]) {
        flag = array[i];
        array[i] = array[i + 1];
        array[i + 1] = flag;
        flag = 1;
        counter++;
      }
    }
  }
  return counter;
}
