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