import java.util.*; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = Integer.valueOf(sc.nextLine()); int[][] v = new int[n][n]; int[][] mem = new int[n][n];//每点都记录到达此点的最小减速总值 for(int i = 0; i < n; ++i){ String temp = sc.nextLine(); String[] str = temp.split(","); for(int j = 0; j < n; ++j) v[i][j] = Integer.valueOf(str[j]); } for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j){ if(i == 0 && j == 0) mem[0][0] = v[0][0]; else if(i == 0) mem[0][j] = v[0][j] + mem[0][j - 1];//边界直接累加 else if(j == 0) mem[i][0] = v[i][0] + mem[i - 1][0];//边界直接累加 else mem[i][j] = Math.min(v[i][j] + mem[i - 1][j], v[i][j] + mem[i][j - 1]); } } System.out.println(mem[n - 1][n - 1]); } }