import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] kari = line.split(" ");
		int r = Integer.parseInt(kari[0]);
		int c = Integer.parseInt(kari[1]);

		int bigsum = 0;

		int[] sum2 = new int[c];

		for (int i = 0; i < r; i++) {
			String s = sc.nextLine();
			String[] k = s.split(" ");
			int[] in = new int[c];
			int[] za = new int[2];
			int sum1 = 0;
			for (int j = 0; j < c; j++) {
				in[j] = Integer.parseInt(k[j]);
				System.out.print(in[j]);
				System.out.print(" ");

				sum1 += in[j];
				sum2[j] += in[j];
			}
			System.out.println(sum1);
			bigsum += sum1;
		}

		for (int i = 0; i < c; i++) {
			System.out.print(sum2[i]);
			System.out.print(" ");
		}

		System.out.println(bigsum);

	}

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