import Data.List
import Debug.Trace

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
solve [] cost   = head cost
solve (x:xs) cost 
    | null cost = solve xs x --top
    | l1<l2     = solve xs cost1'
    | otherwise = solve xs cost2'
        where x' = head xs
              (l1,l2) = (length cost, length x)
              cost1' = [(cost!!0)+(x!!0)]++
                       (map (\i->if (cost!!(i-1))>(cost!!i) then (cost!!(i-1))+(x!!i) else (cost!!i)+(x!!i)) [1..(l2-2)])++
                       [(cost!!(l1-1))+(x!!(l2-1))]
              cost2' = (map (\i->if (cost!!i)>(cost!!(i+1)) then (cost!!i)+(x!!i) else (cost!!(i+1))+(x!!i)) [0..(l2-1)])

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