import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner scan = new Scanner(System.in);
		
		int r = scan.nextInt();
		int c = scan.nextInt();
		
		int A[][] = new int[r][c];
		// ?????????????´?
		for(int i=0; i<r; i++){
			for(int i2=0; i2<c; i2++){
				int x = scan.nextInt();
				A[i][i2] = x;
			}
		}
		// ??????
		int total = 0;
		for(int i=0; i<r; i++){
			int sumr = 0;
			for(int i2=0; i2<c; i2++){
				System.out.print(A[i][i2] + " ");
				sumr = sumr + A[i][i2];
			}
			System.out.println(sumr);
			total = total + sumr;
		}
		for(int i=0; i<c; i++){
			int sumc = 0;
			for(int i2=0; i2<r; i2++){
				sumc = sumc + A[i2][i];
			}
			System.out.print(sumc + " ");
		}
		System.out.println(total);
			
		
	}

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