import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main = do
    n<-readLn::IO Int
    xs<-replicateM n $ unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine
    print $ f n xs
f n xs = maximum $ foldl' p [0,0,0] xs where
    p [u,v,w] [a,b,c] = [u+max b c, v+max a c, w+max a b]
