import Data.List (nub)

main = do
  n <- getLine
  ln <- getLine
  let ps = map (\i -> read i :: Int) $ words ln

  check 0 [ps]

  where
    swap i ps = (take i ps) ++ [ps !! (i + 1), ps !! i] ++ drop (i + 2) ps
    allSwapOnce ps = nub $ map (\i -> swap i ps) [0 .. (length ps) - 1]

    check t pss =
      if any (\ps -> all (\i -> i /= ps !! (i - 1)) [1 .. length ps]) pss
        then print t
        else check (t + 1) $ nub $ foldl (++) [] $ map allSwapOnce pss