n = gets.to_i
until n == 0
    count = 0
    arry = []
    n.times do
        x = gets.to_i
        arry << x
    end
    arrytimes = arry.length
    (arrytimes-1).times do
        for i in 0..(arry.length-2) do
            if arry[i] > arry[i+1]
                k = arry[i]
                arry[i] = arry[i+1]
                arry[i+1] = k
                count += 1
            end 
        end
        arry.pop
    end
    puts count
    n = gets.to_i
end
