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

class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int in[] = parseInts(br.readLine().split(" "));
		int in1[][] = new int[in[0]][in[1]];
		int in2[] = new int[in[1]];
		for(int i=0; i<in[0]; i++){
			in1[i] = parseInts(br.readLine().split(" "));
		}
		for(int n=0; n<in[0]; n++){
			for(int m=0; m<in[1]; m++){
				in2[m] += in1[n][m];
				System.out.print(in1[n][m] + " ");
			}
			System.out.println(sum(in1[n]));
		}
		for(int i=0; i<in[1]; i++){
			System.out.print(in2[i] + " ");
		}
		System.out.println(sum(in2));
	}
	static int[] parseInts(String[] s){
		int[] x = new int[s.length];
		for(int i=0; i<s.length; i++){
			x[i] = Integer.parseInt(s[i]);
		}
		return x;
	}
	static int sum(int[] x){
		int t = 0;
		for(int a : x){
			t += a;
		}
		return t;
	}
} import java.io.*; io.* java import java.util.Arrays; Arrays java.util class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int in[] = parseInts(br.readLine().split(" "));
		int in1[][] = new int[in[0]][in[1]];
		int in2[] = new int[in[1]];
		for(int i=0; i<in[0]; i++){
			in1[i] = parseInts(br.readLine().split(" "));
		}
		for(int n=0; n<in[0]; n++){
			for(int m=0; m<in[1]; m++){
				in2[m] += in1[n][m];
				System.out.print(in1[n][m] + " ");
			}
			System.out.println(sum(in1[n]));
		}
		for(int i=0; i<in[1]; i++){
			System.out.print(in2[i] + " ");
		}
		System.out.println(sum(in2));
	}
	static int[] parseInts(String[] s){
		int[] x = new int[s.length];
		for(int i=0; i<s.length; i++){
			x[i] = Integer.parseInt(s[i]);
		}
		return x;
	}
	static int sum(int[] x){
		int t = 0;
		for(int a : x){
			t += a;
		}
		return t;
	}
} Main public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int in[] = parseInts(br.readLine().split(" "));
		int in1[][] = new int[in[0]][in[1]];
		int in2[] = new int[in[1]];
		for(int i=0; i<in[0]; i++){
			in1[i] = parseInts(br.readLine().split(" "));
		}
		for(int n=0; n<in[0]; n++){
			for(int m=0; m<in[1]; m++){
				in2[m] += in1[n][m];
				System.out.print(in1[n][m] + " ");
			}
			System.out.println(sum(in1[n]));
		}
		for(int i=0; i<in[1]; i++){
			System.out.print(in2[i] + " ");
		}
		System.out.println(sum(in2));
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int in[] = parseInts(br.readLine().split(" "));
		int in1[][] = new int[in[0]][in[1]];
		int in2[] = new int[in[1]];
		for(int i=0; i<in[0]; i++){
			in1[i] = parseInts(br.readLine().split(" "));
		}
		for(int n=0; n<in[0]; n++){
			for(int m=0; m<in[1]; m++){
				in2[m] += in1[n][m];
				System.out.print(in1[n][m] + " ");
			}
			System.out.println(sum(in1[n]));
		}
		for(int i=0; i<in[1]; i++){
			System.out.print(in2[i] + " ");
		}
		System.out.println(sum(in2));
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int in[] = parseInts(br.readLine().split(" ")); in parseInts(br.readLine().split(" ")) parseInts br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int in1[][] = new int[in[0]][in[1]]; in1 new int[in[0]][in[1]] in[0] in 0 in[1] in 1 int in2[] = new int[in[1]]; in2 new int[in[1]] in[1] in 1 for(int i=0; i<in[0]; i++){
			in1[i] = parseInts(br.readLine().split(" "));
		} int i=0; int i=0; i 0 i<in[0] i in[0] in 0 i++ i++ i {
			in1[i] = parseInts(br.readLine().split(" "));
		} {
			in1[i] = parseInts(br.readLine().split(" "));
		} in1[i] = parseInts(br.readLine().split(" ")) in1[i] in1 i parseInts(br.readLine().split(" ")) parseInts br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int n=0; n<in[0]; n++){
			for(int m=0; m<in[1]; m++){
				in2[m] += in1[n][m];
				System.out.print(in1[n][m] + " ");
			}
			System.out.println(sum(in1[n]));
		} int n=0; int n=0; n 0 n<in[0] n in[0] in 0 n++ n++ n {
			for(int m=0; m<in[1]; m++){
				in2[m] += in1[n][m];
				System.out.print(in1[n][m] + " ");
			}
			System.out.println(sum(in1[n]));
		} {
			for(int m=0; m<in[1]; m++){
				in2[m] += in1[n][m];
				System.out.print(in1[n][m] + " ");
			}
			System.out.println(sum(in1[n]));
		} for(int m=0; m<in[1]; m++){
				in2[m] += in1[n][m];
				System.out.print(in1[n][m] + " ");
			} int m=0; int m=0; m 0 m<in[1] m in[1] in 1 m++ m++ m {
				in2[m] += in1[n][m];
				System.out.print(in1[n][m] + " ");
			} {
				in2[m] += in1[n][m];
				System.out.print(in1[n][m] + " ");
			} in2[m] += in1[n][m] in2[m] in2 m in1[n][m] in1[n] in1 n m System.out.print(in1[n][m] + " ") System.out.print System.out System System.out in1[n][m] + " " in1[n][m] in1[n] in1 n m " " System.out.println(sum(in1[n])) System.out.println System.out System System.out sum(in1[n]) sum in1[n] in1 n for(int i=0; i<in[1]; i++){
			System.out.print(in2[i] + " ");
		} int i=0; int i=0; i 0 i<in[1] i in[1] in 1 i++ i++ i {
			System.out.print(in2[i] + " ");
		} {
			System.out.print(in2[i] + " ");
		} System.out.print(in2[i] + " ") System.out.print System.out System System.out in2[i] + " " in2[i] in2 i " " System.out.println(sum(in2)) System.out.println System.out System System.out sum(in2) sum in2 String[] args args static int[] parseInts(String[] s){
		int[] x = new int[s.length];
		for(int i=0; i<s.length; i++){
			x[i] = Integer.parseInt(s[i]);
		}
		return x;
	} parseInts {
		int[] x = new int[s.length];
		for(int i=0; i<s.length; i++){
			x[i] = Integer.parseInt(s[i]);
		}
		return x;
	} int[] x = new int[s.length]; x new int[s.length] s.length s s.length for(int i=0; i<s.length; i++){
			x[i] = Integer.parseInt(s[i]);
		} int i=0; int i=0; i 0 i<s.length i s.length s s.length i++ i++ i {
			x[i] = Integer.parseInt(s[i]);
		} {
			x[i] = Integer.parseInt(s[i]);
		} x[i] = Integer.parseInt(s[i]) x[i] x i Integer.parseInt(s[i]) Integer.parseInt Integer s[i] s i return x; x String[] s s static int sum(int[] x){
		int t = 0;
		for(int a : x){
			t += a;
		}
		return t;
	} sum {
		int t = 0;
		for(int a : x){
			t += a;
		}
		return t;
	} int t = 0; t 0 for(int a : x){
			t += a;
		} int a x {
			t += a;
		} {
			t += a;
		} t += a t a return t; t int[] x x
import java.io.*;
import java.util.Arrays;

class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int in[] = parseInts(br.readLine().split(" "));
		int in1[][] = new int[in[0]][in[1]];
		int in2[] = new int[in[1]];
		for(int i=0; i<in[0]; i++){
			in1[i] = parseInts(br.readLine().split(" "));
		}
		for(int n=0; n<in[0]; n++){
			for(int m=0; m<in[1]; m++){
				in2[m] += in1[n][m];
				System.out.print(in1[n][m] + " ");
			}
			System.out.println(sum(in1[n]));
		}
		for(int i=0; i<in[1]; i++){
			System.out.print(in2[i] + " ");
		}
		System.out.println(sum(in2));
	}
	static int[] parseInts(String[] s){
		int[] x = new int[s.length];
		for(int i=0; i<s.length; i++){
			x[i] = Integer.parseInt(s[i]);
		}
		return x;
	}
	static int sum(int[] x){
		int t = 0;
		for(int a : x){
			t += a;
		}
		return t;
	}
}