import Control.Applicative ((<$>)) import qualified Data.ByteString.Lazy.Char8 as LC import Data.Maybe (fromJust) unsafeReadInt :: LC.ByteString -> Int unsafeReadInt = fst . fromJust . LC.readInt minNumOfOps :: Integral a => a -> [a] -> a minNumOfOps = foldr (\x t -> if x == t then t - 1 else t) main :: IO () main = do d <- fmap unsafeReadInt . LC.words <$> LC.getContents print . minNumOfOps (head d) $ tail d