import java.util.*;
public class Main{
    public static void main(String[]args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int[][] cell;
    int h, w;
    int i, j;
    
    void run(){
	while(sc.hasNext()){
	    h = sc.nextInt();
	    w = sc.nextInt();
	    if(h!=0 && w!=0){
		cell = new int[h+1][w+1];
		solve();
	    }
	}
    }

    void solve(){
	for(i=0; i<h; i++){
	    for(j=0; j<w; j++){
		cell[i][j] = sc.nextInt();
		cell[h][j] += cell[i][j];
		cell[i][w] += cell[i][j];
		cell[h][w] += cell[i][j];
	    }
	}
	print();
    }

    void print(){
	for(i=0; i<=h; i++){
	    for(j=0; j<=w; j++){
		System.out.print(cell[i][j]);
		if(j+1<=w)
		    System.out.print(" ");
	    }
	    System.out.println();
	}
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[]args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int[][] cell;
    int h, w;
    int i, j;
    
    void run(){
	while(sc.hasNext()){
	    h = sc.nextInt();
	    w = sc.nextInt();
	    if(h!=0 && w!=0){
		cell = new int[h+1][w+1];
		solve();
	    }
	}
    }

    void solve(){
	for(i=0; i<h; i++){
	    for(j=0; j<w; j++){
		cell[i][j] = sc.nextInt();
		cell[h][j] += cell[i][j];
		cell[i][w] += cell[i][j];
		cell[h][w] += cell[i][j];
	    }
	}
	print();
    }

    void print(){
	for(i=0; i<=h; i++){
	    for(j=0; j<=w; j++){
		System.out.print(cell[i][j]);
		if(j+1<=w)
		    System.out.print(" ");
	    }
	    System.out.println();
	}
    }
} Main Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int[][] cell; cell int h h w; w int i i j; j public static void main(String[]args){
	new Main().run();
    } main {
	new Main().run();
    } new Main().run() new Main().run new Main() String[]args args void run(){
	while(sc.hasNext()){
	    h = sc.nextInt();
	    w = sc.nextInt();
	    if(h!=0 && w!=0){
		cell = new int[h+1][w+1];
		solve();
	    }
	}
    } run {
	while(sc.hasNext()){
	    h = sc.nextInt();
	    w = sc.nextInt();
	    if(h!=0 && w!=0){
		cell = new int[h+1][w+1];
		solve();
	    }
	}
    } while(sc.hasNext()){
	    h = sc.nextInt();
	    w = sc.nextInt();
	    if(h!=0 && w!=0){
		cell = new int[h+1][w+1];
		solve();
	    }
	} sc.hasNext() sc.hasNext sc {
	    h = sc.nextInt();
	    w = sc.nextInt();
	    if(h!=0 && w!=0){
		cell = new int[h+1][w+1];
		solve();
	    }
	} h = sc.nextInt() h sc.nextInt() sc.nextInt sc w = sc.nextInt() w sc.nextInt() sc.nextInt sc if(h!=0 && w!=0){
		cell = new int[h+1][w+1];
		solve();
	    } h!=0 && w!=0 h!=0 h 0 w!=0 w 0 {
		cell = new int[h+1][w+1];
		solve();
	    } cell = new int[h+1][w+1] cell new int[h+1][w+1] h+1 h 1 w+1 w 1 solve() solve void solve(){
	for(i=0; i<h; i++){
	    for(j=0; j<w; j++){
		cell[i][j] = sc.nextInt();
		cell[h][j] += cell[i][j];
		cell[i][w] += cell[i][j];
		cell[h][w] += cell[i][j];
	    }
	}
	print();
    } solve {
	for(i=0; i<h; i++){
	    for(j=0; j<w; j++){
		cell[i][j] = sc.nextInt();
		cell[h][j] += cell[i][j];
		cell[i][w] += cell[i][j];
		cell[h][w] += cell[i][j];
	    }
	}
	print();
    } for(i=0; i<h; i++){
	    for(j=0; j<w; j++){
		cell[i][j] = sc.nextInt();
		cell[h][j] += cell[i][j];
		cell[i][w] += cell[i][j];
		cell[h][w] += cell[i][j];
	    }
	} i=0; i=0 i 0 i<h i h i++ i++ i {
	    for(j=0; j<w; j++){
		cell[i][j] = sc.nextInt();
		cell[h][j] += cell[i][j];
		cell[i][w] += cell[i][j];
		cell[h][w] += cell[i][j];
	    }
	} {
	    for(j=0; j<w; j++){
		cell[i][j] = sc.nextInt();
		cell[h][j] += cell[i][j];
		cell[i][w] += cell[i][j];
		cell[h][w] += cell[i][j];
	    }
	} for(j=0; j<w; j++){
		cell[i][j] = sc.nextInt();
		cell[h][j] += cell[i][j];
		cell[i][w] += cell[i][j];
		cell[h][w] += cell[i][j];
	    } j=0; j=0 j 0 j<w j w j++ j++ j {
		cell[i][j] = sc.nextInt();
		cell[h][j] += cell[i][j];
		cell[i][w] += cell[i][j];
		cell[h][w] += cell[i][j];
	    } {
		cell[i][j] = sc.nextInt();
		cell[h][j] += cell[i][j];
		cell[i][w] += cell[i][j];
		cell[h][w] += cell[i][j];
	    } cell[i][j] = sc.nextInt() cell[i][j] cell[i] cell i j sc.nextInt() sc.nextInt sc cell[h][j] += cell[i][j] cell[h][j] cell[h] cell h j cell[i][j] cell[i] cell i j cell[i][w] += cell[i][j] cell[i][w] cell[i] cell i w cell[i][j] cell[i] cell i j cell[h][w] += cell[i][j] cell[h][w] cell[h] cell h w cell[i][j] cell[i] cell i j print() print void print(){
	for(i=0; i<=h; i++){
	    for(j=0; j<=w; j++){
		System.out.print(cell[i][j]);
		if(j+1<=w)
		    System.out.print(" ");
	    }
	    System.out.println();
	}
    } print {
	for(i=0; i<=h; i++){
	    for(j=0; j<=w; j++){
		System.out.print(cell[i][j]);
		if(j+1<=w)
		    System.out.print(" ");
	    }
	    System.out.println();
	}
    } for(i=0; i<=h; i++){
	    for(j=0; j<=w; j++){
		System.out.print(cell[i][j]);
		if(j+1<=w)
		    System.out.print(" ");
	    }
	    System.out.println();
	} i=0; i=0 i 0 i<=h i h i++ i++ i {
	    for(j=0; j<=w; j++){
		System.out.print(cell[i][j]);
		if(j+1<=w)
		    System.out.print(" ");
	    }
	    System.out.println();
	} {
	    for(j=0; j<=w; j++){
		System.out.print(cell[i][j]);
		if(j+1<=w)
		    System.out.print(" ");
	    }
	    System.out.println();
	} for(j=0; j<=w; j++){
		System.out.print(cell[i][j]);
		if(j+1<=w)
		    System.out.print(" ");
	    } j=0; j=0 j 0 j<=w j w j++ j++ j {
		System.out.print(cell[i][j]);
		if(j+1<=w)
		    System.out.print(" ");
	    } {
		System.out.print(cell[i][j]);
		if(j+1<=w)
		    System.out.print(" ");
	    } System.out.print(cell[i][j]) System.out.print System.out System System.out cell[i][j] cell[i] cell i j if(j+1<=w)
		    System.out.print(" "); j+1<=w j+1 j 1 w System.out.print(" ") System.out.print System.out System System.out " " System.out.println() System.out.println System.out System System.out public class Main{
    public static void main(String[]args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int[][] cell;
    int h, w;
    int i, j;
    
    void run(){
	while(sc.hasNext()){
	    h = sc.nextInt();
	    w = sc.nextInt();
	    if(h!=0 && w!=0){
		cell = new int[h+1][w+1];
		solve();
	    }
	}
    }

    void solve(){
	for(i=0; i<h; i++){
	    for(j=0; j<w; j++){
		cell[i][j] = sc.nextInt();
		cell[h][j] += cell[i][j];
		cell[i][w] += cell[i][j];
		cell[h][w] += cell[i][j];
	    }
	}
	print();
    }

    void print(){
	for(i=0; i<=h; i++){
	    for(j=0; j<=w; j++){
		System.out.print(cell[i][j]);
		if(j+1<=w)
		    System.out.print(" ");
	    }
	    System.out.println();
	}
    }
} public class Main{
    public static void main(String[]args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int[][] cell;
    int h, w;
    int i, j;
    
    void run(){
	while(sc.hasNext()){
	    h = sc.nextInt();
	    w = sc.nextInt();
	    if(h!=0 && w!=0){
		cell = new int[h+1][w+1];
		solve();
	    }
	}
    }

    void solve(){
	for(i=0; i<h; i++){
	    for(j=0; j<w; j++){
		cell[i][j] = sc.nextInt();
		cell[h][j] += cell[i][j];
		cell[i][w] += cell[i][j];
		cell[h][w] += cell[i][j];
	    }
	}
	print();
    }

    void print(){
	for(i=0; i<=h; i++){
	    for(j=0; j<=w; j++){
		System.out.print(cell[i][j]);
		if(j+1<=w)
		    System.out.print(" ");
	    }
	    System.out.println();
	}
    }
} Main
import java.util.*;
public class Main{
    public static void main(String[]args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int[][] cell;
    int h, w;
    int i, j;
    
    void run(){
	while(sc.hasNext()){
	    h = sc.nextInt();
	    w = sc.nextInt();
	    if(h!=0 && w!=0){
		cell = new int[h+1][w+1];
		solve();
	    }
	}
    }

    void solve(){
	for(i=0; i<h; i++){
	    for(j=0; j<w; j++){
		cell[i][j] = sc.nextInt();
		cell[h][j] += cell[i][j];
		cell[i][w] += cell[i][j];
		cell[h][w] += cell[i][j];
	    }
	}
	print();
    }

    void print(){
	for(i=0; i<=h; i++){
	    for(j=0; j<=w; j++){
		System.out.print(cell[i][j]);
		if(j+1<=w)
		    System.out.print(" ");
	    }
	    System.out.println();
	}
    }
}