import java.io.*;

public class Main {
    public static void main(String[] args){
        test2_1();

    }

    private static int test1_1(String i){
        int num = Integer.parseInt(i);
        int three_num = num*num*num;
        return three_num;
    }

    private static void test2_1(){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String word;
        String[] dat;
        try {
            //word = reader.readLine();
            dat = reader.readLine().split(" ");
            int r = Integer.parseInt(dat[0]);
            int c = Integer.parseInt(dat[1]);
            StringBuilder out=new StringBuilder();
            int g,p,gg=0;
            String str;
            int[] SumC=new int[c];
            for (int i=0;i<r;i++){
                str =reader.readLine();
                dat = str.split(" ");
                g=0;
                for (int j=0;j<c;j++){
                    p=Integer.parseInt(dat[j]);
                    g += p;
                    SumC[j] += p;
                }
                gg+=g;
                out.append(str+" "+g+"\n");
            }
            for (int j=0;j<c;j++) out.append(SumC[j]+" ");
            out.append(gg);
            System.out.println(out);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
} import java.io.*; io.* java public class Main {
    public static void main(String[] args){
        test2_1();

    }

    private static int test1_1(String i){
        int num = Integer.parseInt(i);
        int three_num = num*num*num;
        return three_num;
    }

    private static void test2_1(){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String word;
        String[] dat;
        try {
            //word = reader.readLine();
            dat = reader.readLine().split(" ");
            int r = Integer.parseInt(dat[0]);
            int c = Integer.parseInt(dat[1]);
            StringBuilder out=new StringBuilder();
            int g,p,gg=0;
            String str;
            int[] SumC=new int[c];
            for (int i=0;i<r;i++){
                str =reader.readLine();
                dat = str.split(" ");
                g=0;
                for (int j=0;j<c;j++){
                    p=Integer.parseInt(dat[j]);
                    g += p;
                    SumC[j] += p;
                }
                gg+=g;
                out.append(str+" "+g+"\n");
            }
            for (int j=0;j<c;j++) out.append(SumC[j]+" ");
            out.append(gg);
            System.out.println(out);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
} Main public static void main(String[] args){
        test2_1();

    } main {
        test2_1();

    } test2_1() test2_1 String[] args args private static int test1_1(String i){
        int num = Integer.parseInt(i);
        int three_num = num*num*num;
        return three_num;
    } test1_1 {
        int num = Integer.parseInt(i);
        int three_num = num*num*num;
        return three_num;
    } int num = Integer.parseInt(i); num Integer.parseInt(i) Integer.parseInt Integer i int three_num = num*num*num; three_num num*num*num num*num*num num num num return three_num; three_num String i i private static void test2_1(){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String word;
        String[] dat;
        try {
            //word = reader.readLine();
            dat = reader.readLine().split(" ");
            int r = Integer.parseInt(dat[0]);
            int c = Integer.parseInt(dat[1]);
            StringBuilder out=new StringBuilder();
            int g,p,gg=0;
            String str;
            int[] SumC=new int[c];
            for (int i=0;i<r;i++){
                str =reader.readLine();
                dat = str.split(" ");
                g=0;
                for (int j=0;j<c;j++){
                    p=Integer.parseInt(dat[j]);
                    g += p;
                    SumC[j] += p;
                }
                gg+=g;
                out.append(str+" "+g+"\n");
            }
            for (int j=0;j<c;j++) out.append(SumC[j]+" ");
            out.append(gg);
            System.out.println(out);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    } test2_1 {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String word;
        String[] dat;
        try {
            //word = reader.readLine();
            dat = reader.readLine().split(" ");
            int r = Integer.parseInt(dat[0]);
            int c = Integer.parseInt(dat[1]);
            StringBuilder out=new StringBuilder();
            int g,p,gg=0;
            String str;
            int[] SumC=new int[c];
            for (int i=0;i<r;i++){
                str =reader.readLine();
                dat = str.split(" ");
                g=0;
                for (int j=0;j<c;j++){
                    p=Integer.parseInt(dat[j]);
                    g += p;
                    SumC[j] += p;
                }
                gg+=g;
                out.append(str+" "+g+"\n");
            }
            for (int j=0;j<c;j++) out.append(SumC[j]+" ");
            out.append(gg);
            System.out.println(out);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    } BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) String[] dat; dat try {
            //word = reader.readLine();
            dat = reader.readLine().split(" ");
            int r = Integer.parseInt(dat[0]);
            int c = Integer.parseInt(dat[1]);
            StringBuilder out=new StringBuilder();
            int g,p,gg=0;
            String str;
            int[] SumC=new int[c];
            for (int i=0;i<r;i++){
                str =reader.readLine();
                dat = str.split(" ");
                g=0;
                for (int j=0;j<c;j++){
                    p=Integer.parseInt(dat[j]);
                    g += p;
                    SumC[j] += p;
                }
                gg+=g;
                out.append(str+" "+g+"\n");
            }
            for (int j=0;j<c;j++) out.append(SumC[j]+" ");
            out.append(gg);
            System.out.println(out);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } IOException e {
            e.printStackTrace();
        } e.printStackTrace() e.printStackTrace e {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } IOException e {
                e.printStackTrace();
            } e.printStackTrace() e.printStackTrace e {
                reader.close();
            } reader.close() reader.close reader {
            //word = reader.readLine();
            dat = reader.readLine().split(" ");
            int r = Integer.parseInt(dat[0]);
            int c = Integer.parseInt(dat[1]);
            StringBuilder out=new StringBuilder();
            int g,p,gg=0;
            String str;
            int[] SumC=new int[c];
            for (int i=0;i<r;i++){
                str =reader.readLine();
                dat = str.split(" ");
                g=0;
                for (int j=0;j<c;j++){
                    p=Integer.parseInt(dat[j]);
                    g += p;
                    SumC[j] += p;
                }
                gg+=g;
                out.append(str+" "+g+"\n");
            }
            for (int j=0;j<c;j++) out.append(SumC[j]+" ");
            out.append(gg);
            System.out.println(out);
        } dat = reader.readLine().split(" ") dat reader.readLine().split(" ") reader.readLine().split reader.readLine() reader.readLine reader " " int r = Integer.parseInt(dat[0]); r Integer.parseInt(dat[0]) Integer.parseInt Integer dat[0] dat 0 int c = Integer.parseInt(dat[1]); c Integer.parseInt(dat[1]) Integer.parseInt Integer dat[1] dat 1 StringBuilder out=new StringBuilder(); out new StringBuilder() int g g p p gg=0; gg 0 String str; str int[] SumC=new int[c]; SumC new int[c] c for (int i=0;i<r;i++){
                str =reader.readLine();
                dat = str.split(" ");
                g=0;
                for (int j=0;j<c;j++){
                    p=Integer.parseInt(dat[j]);
                    g += p;
                    SumC[j] += p;
                }
                gg+=g;
                out.append(str+" "+g+"\n");
            } int i=0; int i=0; i 0 i<r i r i++ i++ i {
                str =reader.readLine();
                dat = str.split(" ");
                g=0;
                for (int j=0;j<c;j++){
                    p=Integer.parseInt(dat[j]);
                    g += p;
                    SumC[j] += p;
                }
                gg+=g;
                out.append(str+" "+g+"\n");
            } {
                str =reader.readLine();
                dat = str.split(" ");
                g=0;
                for (int j=0;j<c;j++){
                    p=Integer.parseInt(dat[j]);
                    g += p;
                    SumC[j] += p;
                }
                gg+=g;
                out.append(str+" "+g+"\n");
            } str =reader.readLine() str reader.readLine() reader.readLine reader dat = str.split(" ") dat str.split(" ") str.split str " " g=0 g 0 for (int j=0;j<c;j++){
                    p=Integer.parseInt(dat[j]);
                    g += p;
                    SumC[j] += p;
                } int j=0; int j=0; j 0 j<c j c j++ j++ j {
                    p=Integer.parseInt(dat[j]);
                    g += p;
                    SumC[j] += p;
                } {
                    p=Integer.parseInt(dat[j]);
                    g += p;
                    SumC[j] += p;
                } p=Integer.parseInt(dat[j]) p Integer.parseInt(dat[j]) Integer.parseInt Integer dat[j] dat j g += p g p SumC[j] += p SumC[j] SumC j p gg+=g gg g out.append(str+" "+g+"\n") out.append out str+" "+g+"\n" g str+" "+g+"\n" str " " g "\n" for (int j=0;j<c;j++) out.append(SumC[j]+" "); int j=0; int j=0; j 0 j<c j c j++ j++ j out.append(SumC[j]+" "); out.append(SumC[j]+" ") out.append out SumC[j]+" " SumC[j] SumC j " " out.append(gg) out.append out gg System.out.println(out) System.out.println System.out System System.out out public class Main {
    public static void main(String[] args){
        test2_1();

    }

    private static int test1_1(String i){
        int num = Integer.parseInt(i);
        int three_num = num*num*num;
        return three_num;
    }

    private static void test2_1(){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String word;
        String[] dat;
        try {
            //word = reader.readLine();
            dat = reader.readLine().split(" ");
            int r = Integer.parseInt(dat[0]);
            int c = Integer.parseInt(dat[1]);
            StringBuilder out=new StringBuilder();
            int g,p,gg=0;
            String str;
            int[] SumC=new int[c];
            for (int i=0;i<r;i++){
                str =reader.readLine();
                dat = str.split(" ");
                g=0;
                for (int j=0;j<c;j++){
                    p=Integer.parseInt(dat[j]);
                    g += p;
                    SumC[j] += p;
                }
                gg+=g;
                out.append(str+" "+g+"\n");
            }
            for (int j=0;j<c;j++) out.append(SumC[j]+" ");
            out.append(gg);
            System.out.println(out);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
} public class Main {
    public static void main(String[] args){
        test2_1();

    }

    private static int test1_1(String i){
        int num = Integer.parseInt(i);
        int three_num = num*num*num;
        return three_num;
    }

    private static void test2_1(){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String word;
        String[] dat;
        try {
            //word = reader.readLine();
            dat = reader.readLine().split(" ");
            int r = Integer.parseInt(dat[0]);
            int c = Integer.parseInt(dat[1]);
            StringBuilder out=new StringBuilder();
            int g,p,gg=0;
            String str;
            int[] SumC=new int[c];
            for (int i=0;i<r;i++){
                str =reader.readLine();
                dat = str.split(" ");
                g=0;
                for (int j=0;j<c;j++){
                    p=Integer.parseInt(dat[j]);
                    g += p;
                    SumC[j] += p;
                }
                gg+=g;
                out.append(str+" "+g+"\n");
            }
            for (int j=0;j<c;j++) out.append(SumC[j]+" ");
            out.append(gg);
            System.out.println(out);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
} Main
import java.io.*;

public class Main {
    public static void main(String[] args){
        test2_1();

    }

    private static int test1_1(String i){
        int num = Integer.parseInt(i);
        int three_num = num*num*num;
        return three_num;
    }

    private static void test2_1(){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String word;
        String[] dat;
        try {
            //word = reader.readLine();
            dat = reader.readLine().split(" ");
            int r = Integer.parseInt(dat[0]);
            int c = Integer.parseInt(dat[1]);
            StringBuilder out=new StringBuilder();
            int g,p,gg=0;
            String str;
            int[] SumC=new int[c];
            for (int i=0;i<r;i++){
                str =reader.readLine();
                dat = str.split(" ");
                g=0;
                for (int j=0;j<c;j++){
                    p=Integer.parseInt(dat[j]);
                    g += p;
                    SumC[j] += p;
                }
                gg+=g;
                out.append(str+" "+g+"\n");
            }
            for (int j=0;j<c;j++) out.append(SumC[j]+" ");
            out.append(gg);
            System.out.println(out);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}