import java.util.*;

class Main {
	public static void main(String[] arg){
		Scanner in = new Scanner(System.in);
		int r = Integer.parseInt(in.next());
		int c = Integer.parseInt(in.next());
		int[][] table = new int[r+1][c+1];

		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][j] =  Integer.parseInt(in.next());
			}
		}
		
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][c] = table[i][c] + table[i][j];
			}
		}

		for(int i=0;i<r;i++){
			for(int j=0;j<c+1;j++){
				table[r][j] = table[r][j] + table[i][j];
			}
		}
		
		
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c+1;j++){
				if(c==j) System.out.println(table[i][j]);
				else  System.out.print(table[i][j]+" ");
			}
		}


	}	
} import java.util.*; util.* java class Main {
	public static void main(String[] arg){
		Scanner in = new Scanner(System.in);
		int r = Integer.parseInt(in.next());
		int c = Integer.parseInt(in.next());
		int[][] table = new int[r+1][c+1];

		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][j] =  Integer.parseInt(in.next());
			}
		}
		
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][c] = table[i][c] + table[i][j];
			}
		}

		for(int i=0;i<r;i++){
			for(int j=0;j<c+1;j++){
				table[r][j] = table[r][j] + table[i][j];
			}
		}
		
		
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c+1;j++){
				if(c==j) System.out.println(table[i][j]);
				else  System.out.print(table[i][j]+" ");
			}
		}


	}	
} Main public static void main(String[] arg){
		Scanner in = new Scanner(System.in);
		int r = Integer.parseInt(in.next());
		int c = Integer.parseInt(in.next());
		int[][] table = new int[r+1][c+1];

		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][j] =  Integer.parseInt(in.next());
			}
		}
		
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][c] = table[i][c] + table[i][j];
			}
		}

		for(int i=0;i<r;i++){
			for(int j=0;j<c+1;j++){
				table[r][j] = table[r][j] + table[i][j];
			}
		}
		
		
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c+1;j++){
				if(c==j) System.out.println(table[i][j]);
				else  System.out.print(table[i][j]+" ");
			}
		}


	} main {
		Scanner in = new Scanner(System.in);
		int r = Integer.parseInt(in.next());
		int c = Integer.parseInt(in.next());
		int[][] table = new int[r+1][c+1];

		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][j] =  Integer.parseInt(in.next());
			}
		}
		
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][c] = table[i][c] + table[i][j];
			}
		}

		for(int i=0;i<r;i++){
			for(int j=0;j<c+1;j++){
				table[r][j] = table[r][j] + table[i][j];
			}
		}
		
		
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c+1;j++){
				if(c==j) System.out.println(table[i][j]);
				else  System.out.print(table[i][j]+" ");
			}
		}


	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int r = Integer.parseInt(in.next()); r Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in int c = Integer.parseInt(in.next()); c Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in int[][] table = new int[r+1][c+1]; table new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][j] =  Integer.parseInt(in.next());
			}
		} int i=0; int i=0; i 0 i<r i r i++ i++ i {
			for(int j=0;j<c;j++){
				table[i][j] =  Integer.parseInt(in.next());
			}
		} {
			for(int j=0;j<c;j++){
				table[i][j] =  Integer.parseInt(in.next());
			}
		} for(int j=0;j<c;j++){
				table[i][j] =  Integer.parseInt(in.next());
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				table[i][j] =  Integer.parseInt(in.next());
			} {
				table[i][j] =  Integer.parseInt(in.next());
			} table[i][j] =  Integer.parseInt(in.next()) table[i][j] table[i] table i j Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][c] = table[i][c] + table[i][j];
			}
		} int i=0; int i=0; i 0 i<r i r i++ i++ i {
			for(int j=0;j<c;j++){
				table[i][c] = table[i][c] + table[i][j];
			}
		} {
			for(int j=0;j<c;j++){
				table[i][c] = table[i][c] + table[i][j];
			}
		} for(int j=0;j<c;j++){
				table[i][c] = table[i][c] + table[i][j];
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				table[i][c] = table[i][c] + table[i][j];
			} {
				table[i][c] = table[i][c] + table[i][j];
			} table[i][c] = table[i][c] + table[i][j] table[i][c] table[i] table i c table[i][c] + table[i][j] table[i][c] table[i] table i c table[i][j] table[i] table i j for(int i=0;i<r;i++){
			for(int j=0;j<c+1;j++){
				table[r][j] = table[r][j] + table[i][j];
			}
		} int i=0; int i=0; i 0 i<r i r i++ i++ i {
			for(int j=0;j<c+1;j++){
				table[r][j] = table[r][j] + table[i][j];
			}
		} {
			for(int j=0;j<c+1;j++){
				table[r][j] = table[r][j] + table[i][j];
			}
		} for(int j=0;j<c+1;j++){
				table[r][j] = table[r][j] + table[i][j];
			} int j=0; int j=0; j 0 j<c+1 j c+1 c 1 j++ j++ j {
				table[r][j] = table[r][j] + table[i][j];
			} {
				table[r][j] = table[r][j] + table[i][j];
			} table[r][j] = table[r][j] + table[i][j] table[r][j] table[r] table r j table[r][j] + table[i][j] table[r][j] table[r] table r j table[i][j] table[i] table i j for(int i=0;i<r+1;i++){
			for(int j=0;j<c+1;j++){
				if(c==j) System.out.println(table[i][j]);
				else  System.out.print(table[i][j]+" ");
			}
		} int i=0; int i=0; i 0 i<r+1 i r+1 r 1 i++ i++ i {
			for(int j=0;j<c+1;j++){
				if(c==j) System.out.println(table[i][j]);
				else  System.out.print(table[i][j]+" ");
			}
		} {
			for(int j=0;j<c+1;j++){
				if(c==j) System.out.println(table[i][j]);
				else  System.out.print(table[i][j]+" ");
			}
		} for(int j=0;j<c+1;j++){
				if(c==j) System.out.println(table[i][j]);
				else  System.out.print(table[i][j]+" ");
			} int j=0; int j=0; j 0 j<c+1 j c+1 c 1 j++ j++ j {
				if(c==j) System.out.println(table[i][j]);
				else  System.out.print(table[i][j]+" ");
			} {
				if(c==j) System.out.println(table[i][j]);
				else  System.out.print(table[i][j]+" ");
			} if(c==j) System.out.println(table[i][j]);
				else  System.out.print(table[i][j]+" "); c==j c j System.out.println(table[i][j]) System.out.println System.out System System.out table[i][j] table[i] table i j System.out.print(table[i][j]+" ") System.out.print System.out System System.out table[i][j]+" " table[i][j] table[i] table i j " " String[] arg arg
import java.util.*;

class Main {
	public static void main(String[] arg){
		Scanner in = new Scanner(System.in);
		int r = Integer.parseInt(in.next());
		int c = Integer.parseInt(in.next());
		int[][] table = new int[r+1][c+1];

		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][j] =  Integer.parseInt(in.next());
			}
		}
		
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][c] = table[i][c] + table[i][j];
			}
		}

		for(int i=0;i<r;i++){
			for(int j=0;j<c+1;j++){
				table[r][j] = table[r][j] + table[i][j];
			}
		}
		
		
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c+1;j++){
				if(c==j) System.out.println(table[i][j]);
				else  System.out.print(table[i][j]+" ");
			}
		}


	}	
}