def solve array
  count = 0

  (array.size - 1).step(1, -1) do |i|
    i.times do |j|
      if array[j] > array[j + 1]
        tmp = array[j + 1]
        array[j + 1] = array[j]
        array[j] = tmp
        count += 1
      end
    end
  end
  count
end

while (n = $stdin.gets.to_i) != 0 do
  array = Array.new
  n.times do
    array << $stdin.gets.to_i
  end
  p solve(array)
end