#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n && n) {
    vector<int> a;
    int temp, count = 0;
    for (int i = 0; i < n; i++) {
      cin >> temp;
      a.push_back(temp);
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (a[i] > a[j]) {
          count++;
          swap(a[i], a[j]);
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}
