import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap as IM
main=print.solve.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve=IM.foldrWithKey f 0.IM.fromListWith(+).map(flip(,)1).tail
f k v r=r+if k>v then v else v-k