import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int numR;
		int numC;
		int add = 0;

		String outPut = "";

		int[][] tableList;

		Scanner sc = null;

		try {
			//??\????????????
			sc = new Scanner(System.in);

			numR = sc.nextInt();
			numC = sc.nextInt();

			//???????????°??¨
			//System.out.println(numR + " " + numC);

			//??¨??????????????£?¨?
			tableList = new int[numR + 1][numC + 1];

				//??¨?????\??????????????????
				for (int i = 0; i < numR; i++) {

					for (int j = 0; j < numC; j++) {
						tableList[i][j] = sc.nextInt();
						add += tableList[i][j];
					}
					//??????????¨???????????´?
					tableList[i][numC] =add;

					//??????????¨???????????´?
					for (int k = 0; k < tableList[0].length; k++) {
						tableList[numR][k] += tableList[i][k];
					}
					//????¨???????????????????
					add = 0;
				}

				//??¨?????????
				for (int i = 0; i < tableList.length; i++) {
					for (int j = 0; j < tableList[0].length; j++) {

						if (!outPut.equals("")) {
							outPut += " ";
						}
						outPut += tableList[i][j];

					}
					System.out.println(outPut);
					outPut = "";
				}

			}finally {
				sc.close();
			}
	}

}
/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