#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int a[120];
int n;
int cnt = 0;
void bubblesort() {
  for (int i = 0; i < n; i++) {
    int pos = 0;
    while (a[pos] > a[pos + 1] && pos < (n - i - 1)) {
      swap(a[pos], a[pos + 1]);
      pos++;
      cnt++;
    }
  }
}
int main() {
  while (cin >> n, n) {
    cnt = 0;
    for (int i = 0; i < 120; i++) {
      a[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    bubblesort();
    cout << cnt << endl;
  }
  return 0;
}
