import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextLine()){
            int n = Integer.parseInt(sc.nextLine());
            int[][] num = new int[n][n];
            for(int i = 0; i < n; ++i){
                String[] ss = sc.nextLine().split(",");
                for(int j = 0; j < ss.length; ++j){
                    num[i][j] = Integer.parseInt(ss[j]);
                }
            }
            int[][] dp = new int[n][n];
            for(int i = 0; i < n; ++i){
                for(int j = 0; j < n; ++j){
                    if(i == 0 && j == 0){
                        dp[i][j] = num[i][j];
                    }else if(i == 0){
                        dp[i][j] = dp[i][j - 1] + num[i][j];
                    }else if(j == 0){
                        dp[i][j] = dp[i - 1][j] + num[i][j];
                    }else{
                        dp[i][j] = Math.min(dp[i - 1][j],dp[i][j - 1]) + num[i][j];
                    }
                }
            }
            System.out.println(dp[n - 1][n - 1]);
        }
    }
}