fun c87(args: Array<String>) {
    val numList = args.drop(1).map { it.split(" ").map { it.toInt() } }

    fun dfs(x: Int, y: Int): Int {
        when {
            x == numList.size - 1 && y == numList[0].size - 1 ->
                return numList[x][y]
            x == numList.size - 1 ->
                return numList[x][y] + dfs(x, y + 1)
            y == numList[0].size - 1 ->
                return numList[x][y] + dfs(x + 1, y)
            else ->
                return Math.max(
                        numList[x][y] + dfs(x, y + 1),
                        numList[x][y] + dfs(x + 1, y))
        }
    }

    println(dfs(0, 0))
}

fun main(args: Array<String>) {
    c87(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}