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

public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] input = br.readLine().split(" ");
		Integer height = Integer.parseInt(input[0]);
		Integer width = Integer.parseInt(input[1]);
		Integer[][] board = new Integer[height][width+1];

		for(int i = 0; i < height; i++){
			String line = br.readLine();
			System.out.print(line + " ");
			String[] numbers = line.split(" ");
			Integer total = 0;
			for(int j = 0; j < width; j++){
				Integer num = Integer.parseInt(numbers[j]);
				total += num;
				board[i][j] = num;
			}
			board[i][width] = total;
			System.out.print(total + "\n");
		}
		for(int i = 0; i <= width; i++){
			Integer result = 0;
			for(int j = 0; j < height; j++){
				result += board[j][i];
			}
			if(i == width){
				System.out.print(result + "\n");
			}
			else{
				System.out.print(result + " ");
			}
		}
	}
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz