using System;
using System.Collections;
using System.Collections.Generic;

using System.Linq;
public class dp_c {

    static DateTime START_TIME;
#if !MYTEST
    public static void Main() {
        START_TIME = DateTime.Now;
        System.Console.WriteLine(Answer());
    }
    public static void debugOut(string str) { }
    public static string ReadLine(){
        return System.Console.ReadLine();
    }
#endif
    public static string Answer() {
        var p = ReadLine().Trim().Split(' ');
        //              1234567890
        // int.MaxValue=2147483647
        var N = int.Parse(p[0]);
        var happy = new int[N + 1][];
        var dp = new int[N + 1][];
        var result = "";
        // init table
        for (var i = 0; i < N; i++) {
            var day = i + 1;
            p = ReadLine().Trim().Split(' ');
            if (i == 0) {
                happy[0] = new int[p.Length];
                dp[0] = new int[p.Length];
            }
            happy[day] = new int[p.Length];
            dp[day] = new int[p.Length];
            for (var j = 0; j < p.Length; j++) {
                happy[day][j] = int.Parse(p[j]);
                dp[day][j] = 0;
            }
        }
        for (var day = 1; day <= N; day++) {
            for (var yesterday = 0; yesterday < happy[day].Length; yesterday++) {
                for (var today = 0; today < happy[day].Length; today++) {
                    if (yesterday == today) continue;
                    dp[day][today] = Math.Max(dp[day][today], dp[day - 1][yesterday] + happy[day][today]);
                }
            }
        }
        result = dp[N].Max().ToString();
        return result;
    }

    #region LOCAL
#if MYTEST
    static System.IO.StreamReader FS = null;
    public static void Main() {
        START_TIME = DateTime.Now;
        if (System.IO.File.Exists("dp_c.txt")) {
            FS = new System.IO.StreamReader("dp_c.txt");
        }
        try {
            while (true) {
                START_TIME = DateTime.Now;
                var testcase = seekNextCase();
                if (!string.IsNullOrEmpty(testcase)) {
                    debugOut($"TEST > {testcase}\n");
                }
                var ans = Answer();
                System.Console.WriteLine(ans);  // debug
                debugOut($"{(DateTime.Now - START_TIME).TotalMilliseconds} msec.\n");
                if (FS != null && !FS.EndOfStream) {
                    var expect = ReadLine();
                    var res = "";
                    if (ans == expect) {
                        res = "OK";
                        Console.ForegroundColor = ConsoleColor.Green;
                    } else {
                        res = "NG";
                        Console.ForegroundColor = ConsoleColor.Red;
                    }
                    debugOut($"{testcase} {res} expect={expect} actual={ans}\n");
                    System.Console.ResetColor();
                }
            }
        } finally {
            System.Console.ResetColor();
            if (FS != null) FS.Close();
        }
    }
    public static void debugOut(string str) {
        System.Console.Error.Write(str);
    }
    public static string ReadLine() {
        if (FS != null && !FS.EndOfStream) {
            var line = FS.ReadLine();
            // debugOut(line + "\n");
            if (FS.EndOfStream) {
                FS.Close();
                FS = null;
            }
            return line;
        }
        debugOut("\nuser input>\n");
        return System.Console.ReadLine();
    }
    public static string seekNextCase() {
        while (FS != null) {
            var line = ReadLine();
            if (line.StartsWith("---")) {
                return line;
            }
        }
        return null;
    }
#endif
    #endregion
}


Measured memory_bytes: 51300