import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int inR, inC;
        int[][] spd;

        inR = Integer.parseInt(scan.next());
        inC = Integer.parseInt(scan.next());

        spd = new int[inR + 1][inC + 1];

        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                spd[i][j] = 0;
            }
        }


        for (int i = 0; i < inR; i++) {
            for (int j = 0; j < inC; j++) {
                spd[i][j] = Integer.parseInt(scan.next());
                spd[inR][j] += spd[i][j];
                spd[i][inC] += spd[i][j];
                spd[inR][inC] += spd[i][j];
            }
        }
        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                System.out.print(spd[i][j]);
                if (j != inC) System.out.print(" ");
            }
            System.out.print("\n");
        }
    }
}


/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