#include <bits/stdc++.h>
using namespace std;
constexpr int kaijyou(const int &n) { return n == 0 ? 1 : n * kaijyou(n - 1); }
int main() {
  int n, t;
  int ans;
  double count;
  while (cin >> n) {
    if (n == 0) return 0;
    int a[n];
    t = 0;
    ans = 0;
    count = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int j = 0; t == 0; j++) {
      if (j + 1 == n) {
        j = 0;
        count += 1;
      }
      if (a[j] > a[j + 1]) {
        swap(a[j], a[j + 1]);
        ans += 1;
      }
      if (count > kaijyou(n)) {
        cout << ans << endl;
        t = 1;
      }
    }
  }
  return 0;
}
