-- Try AtCoder
-- author: Leonardone @ NEETSDKASU

import Data.List (sort)

main = print . solve . map read . words =<< getContents

solve (k:_:xs) = ans where
    split b c []       = c - b
    split b c (x:y:zs) = split (x + b) (y + c) zs
    split b c (y:_)    = y + c - b
    ans = flip (-) 1 . abs . split 0 0 . reverse $ sort xs
    
