import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int gyou = sc.nextInt();
		int retu = sc.nextInt();

		int[][] hyou = new int[gyou][retu];

		for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length;j++) {
				hyou[i][j] = sc.nextInt();
			}
		}

		int[] gyousum = new int[gyou];
		int[] retusum = new int[retu];
		for(int i = 0;i < hyou.length;i++ ){
			for(int j  = 0;j < hyou[i].length;j++) {
				gyousum[i] += hyou[i][j];
				retusum[j] += hyou[i][j];
			}
		}
		for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length; j++) {
				System.out.print(hyou[i][j] + " ");
			}
			System.out.println(gyousum[i]);
		}
		int sum = 0;
		for(int i = 0;i < retusum.length;i++) {
			System.out.print(retusum[i] + " ");
			sum += retusum[i];
		}
		System.out.println(sum);
	}
}
/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