import Data.List

split :: Char->String->[String]
split c str
    | not $ elem c str = [str]
    | otherwise        = word:(split c str')
    where word = takeWhile (/=c) str
          str' = drop ((length word)+1) str

solve :: [[Int]]->Int->[Int]->[Int]
solve (x:xs) i costs 
    | null xs   = costs'
    | l<l'      = (solve xs i costs')++(solve xs (i+1) costs')
    | i==0      = (solve xs i costs')
    | i==(l-1)  = (solve xs (i-1) costs')
    | otherwise = (solve xs (i-1) costs')++(solve xs i costs')
        where costs' = map (+(x!!i)) costs
              (l,l') = (length x, length $ head xs)

main = do
    ss <- getContents
    let lst = map (\x->map (\y->read y::Int) x) $ map (split ',') $ lines ss
    print $ last $ sort $ solve lst 0 [0]