def bubble(a)
    k = 0
    loop do
        new_k = k
        (0..a.size-2).each do |i|
            if a[i] > a[i+1]
                new_k += 1
                a[i], a[i+1] = a[i+1], a[i]
            end
        end
        break if new_k == k
        k = new_k
    end
    k
end

loop do
    n = gets.to_i
    break if n == 0
    a = (1..n).map { gets.to_i }
    p bubble(a)
end