import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strAry = br.readLine().split(" ");
		int r = Integer.parseInt(strAry[0]);
		int c = Integer.parseInt(strAry[1]);
		int[][] table = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			String[] tableAry = br.readLine().split(" ");
			for (int j = 0; j < c; j++) {
				table[i][j] = Integer.parseInt(tableAry[j]);
				table[i][c] += Integer.parseInt(tableAry[j]);
				table[r][j] += Integer.parseInt(tableAry[j]);
			}
			table[r][c] += table[i][c];
		}
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j == c) System.out.println(table[i][j]);
				else System.out.print(table[i][j] + " ");
			}
		}
	}
}
/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