import Control.Monad

main :: IO ()
main = do
  n <- readLn
  if n == 0
    then return ()
    else do
      ls <- replicateM n readLn
      putStrLn (show (bubbleSet (ls,0)))
      main

bubble :: [Int] -> [Int]
bubble [] = []
bubble (x:[]) = [x]
bubble (x:y:r)
  | x <= y = x : (bubble (y:r))
  | otherwise = y : (bubble (x:r)) 

bubbleC :: [Int] -> Int -> Int
bubbleC [] i = i
bubbleC (x:[]) i  = i
bubbleC (x:y:r) i
  | x <= y = bubbleC (y:r) i
  | otherwise = bubbleC (x:r) (i+1)

bubbleSet :: ([Int],Int) -> Int
bubbleSet ([],i) = i
bubbleSet (l,i)  = bubbleSet ((init (bubble l)),(bubbleC l i))