import java.io.*;

class Main {
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] line = br.readLine().split(" ");
			int r = Integer.parseInt(line[0]);
			int c = Integer.parseInt(line[1]);
			int[][] r1 = new int[r][c];
			int sum2;

			for(int i = 0;i < r;i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0;j < c;j++){
					r1[i][j] = 0;
					int a = Integer.parseInt(str[j]);
					r1[i][j] += a;
				}
			}
			for(int i = 0;i < r;i++){
				int sum = 0;
				for(int j = 0;j < c;j++){
					System.out.print(r1[i][j]+" ");
					sum += r1[i][j];
				}
				System.out.println(sum);
			}
			
			sum2 = 0;
			for(int j = 0;j < c;j++){
				int sum = 0;
				for(int i = 0;i < r;i++){
					sum += r1[i][j];
				}
				sum2 += sum;
				System.out.print(sum+" ");
				if(j == c-1){
					System.out.print(sum2);
				}		
			}
		System.out.print("\n");
		} catch (Exception e){
		}
	}
}
/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