module Main where

import Control.Applicative
import Control.Monad
import Data.List (sort)

solve :: [Int] -> Int
solve as = iter 0 as
  where
    iter n xs
        | all (== head xs) xs = n
        | length ev == 1      = iter (n + 1) (ev ++ fmap (+ 1) od)
        | length ev == 2      = iter (n + 1) (fmap (+ 1) ev ++ od)
        | otherwise           = iter (n + 1) ((y + 2) : ys)
      where
        (ev, od) = (filter even xs, filter odd xs)
        (y:ys)   = sort xs

main :: IO ()
main = do
    xs <- fmap read . words <$> getLine :: IO [Int]
    print $ solve xs