#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream i(s);
  i >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream o;
  o << x;
  return o.str();
}
template <class T>
void pv(T a, T b) {
  for (T it = a; it != b; ++it) cerr << *it << " ";
  cerr << endl;
}
const int INF = 1000000000;
const double PI = acos(-1.0), EPS = 1e-10;
int main() {
  for (int N; cin >> N, N;) {
    vector<int> v(N);
    for (int i = 0; i < (int)N; ++i) cin >> v[i];
    int cnt = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N - 1; j++) {
        if (v[j] > v[j + 1]) {
          swap(v[j], v[j + 1]);
          cnt++;
        }
      }
      N--;
    }
    cout << cnt << endl;
  }
}
