import Data.List
main=do
    [k,t]<-map read.words<$>getLine::IO[Int]
    as<-sort.map read.words<$>getLine::IO[Int]
    print $ if length as == 1 then head as -1 else s as
s as
    | null as = 0
    | length as == 1 = max 0 $ head as-2
    | otherwise = s $ filter (/=0) $ map (\n->n-head as) $ tail as