import java.util.Scanner;
class Main{
	public static void main(String args[]){
		int i,j,g,r,x;
		Scanner sc = new Scanner(System.in);
		g=sc.nextInt();
		r=sc.nextInt();
		int[][] map= new int[g+1][r+1];
		for(i=0;i<g+1;i++){
			for(j=0;j<r+1;j++)
			map[i][j]=0;
		}
		for(i=0;i<g;i++){
			for(j=0;j<r;j++)
				map[i][j]=sc.nextInt();
		}
		for(i=0;i<g;i++){
			for(j=0;j<r;j++){
				map[i][r]+=map[i][j];
				map[g][j]+=map[i][j];}
			map[g][r]+=map[i][r];
		}
		for(i=0;i<g+1;i++){
			for(j=0;j<r;j++)
				System.out.print(map[i][j]+" ");
			System.out.println(map[i][r]);
		}
	}
}

/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