import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner( System.in );
		
		// 入力
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		int[][] vector = new int[r + 1][c + 1];
		
		for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][iC] = sc.nextInt();
				
			}
		}
		
		// 計算
		for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][c] += vector[iR][iC];
				
			}
		}
		
		for ( int iC = 0; iC < c; iC++ ) {
			for ( int iR = 0; iR < r; iR++ ) {
				vector[r][iC] += vector[iR][iC];
				vector[r][c] += vector[iR][iC];
			}
		}
				
		// 出力
		for ( int iR = 0; iR < r+1; iR++ ) {
			for ( int iC = 0; iC < c+1; iC++ ) {
				System.out.print(vector[iR][iC]);
				if( iC != c ) {
					System.out.print(" ");
					
				} else {
					System.out.println();
					
				}
			}
		}
		
		sc.close();
	}

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