import java.util.; import java.io.; public class Main{ public static void main(String[] args)throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str = null; while((str = in.readLine())!= null){ String[] arr = str.split(" "); int[] mn = new int[2]; mn[0] = Integer.parseInt(arr[0]); mn[1] = Integer.parseInt(arr[1]); int[][] res = new int[mn[0]][mn[1]]; for(int i = 0;i < mn[0];i++){ String[] temp = in.readLine().split(" "); for(int j = 0;j < mn[1];j++){ res[i][j] = Integer.parseInt(temp[j]); } } int[][] res1 = new int[mn[0]+1][mn[1]+1]; for(int i = 0;i <= mn[1];i++){ res1[0][i] = Integer.MAX_VALUE; } for(int i = 0;i <= mn[0];i++){ res1[i][0] = Integer.MAX_VALUE; } res1[0][1] = 0; for(int i = 1;i <= mn[0];i++){ for(int j = 1;j <=mn[1];j++){ res1[i][j] = Math.min(res1[i-1][j],res1[i][j-1])+res[i-1][j-1]; } } System.out.println(res1[mn[0]][mn[1]]); } } }