#include <bits/stdc++.h>
int bubble(long d[101], int n) {
  int i, j;
  int t, count = 0, h;
  h = n;
  for (i = 0; i < h; i = 0, h--) {
    for (j = i + 1; j < n; j++) {
      if (d[i] > d[j]) {
        count++;
        t = d[i];
        d[i] = d[j];
        d[j] = t;
        i++;
      }
    }
  }
  return count;
}
int main() {
  long d[101];
  int i, j, n;
  int c;
  for (; scanf("%d", &n) && n;) {
    for (i = 0; i < n; i++) {
      scanf("%ld", &d[i]);
    }
    c = bubble(d, n);
    printf("%d\n", c);
  }
  return 0;
}
