using System;



class Program
{
    static void Main(string[] args)
    {
        Input CInput = new Input();
        //EasyTask CEasyTask = new EasyTask();
        //int input = 0;
        //int[] input = new int[(int)Input.Define.MAX_ArraySize];
        //int[,] input = new int[(int)Input.Define.MAX_ArraySize, (int)Input.Define.ArraySize2d];
        //int num = 0;
        //input = CInput.Line1_int();
        //input = CInput.Multiline_int(' ', 2, ref num);


        int[] input1 = new int[(int)Input.Define.MAX_ArraySize];
        int[,] input2 = new int[(int)Input.Define.MAX_ArraySize, (int)Input.Define.ArraySize2d];
        //int input3_count = 0;

        int[] bufDB = new int[100];

        int value = 0, sum = 0;
        input1 = CInput.Line1_int(' ', 2);
        input2 = CInput.Multiline_int(' ', input1[1], input1[0]);

        for (int i = 0; i < input1[0]; i++)
        {
            for (int j = 0; j < input1[1]; j++)
            {
                System.Console.Write("{0} ", input2[i, j]);
                value += input2[i, j];
                bufDB[j] += input2[i, j];
            }
            System.Console.WriteLine(value);
            sum += value;
            value = 0;
        }
        for (int i = 0; i < input1[1]; i++)
        {
            System.Console.Write("{0} ", bufDB[i]);
        }
        System.Console.WriteLine(sum);

    }
}








class Input
{
    public enum Define
    {
        MAX_ArraySize = 100,
        ArraySize2d = 100,                // 2?¬?????????????[][?] ???????
    }

    public string Line1_string()
    {
        return Console.ReadLine();
    }

    public string[] Line1_string(int chr)
    {
        var input = Console.ReadLine();
        var split = input.Split(' ');
        return split;
    }

    public int Line1_int()
    {
        var input = Console.ReadLine();
        return int.Parse(input);
    }

    public double Line1_double()
    {
        var input = Console.ReadLine();
        return double.Parse(input);
    }

    public int[] Line1_int(int chr, int num)
    {
        var input = Console.ReadLine();
        var split = input.Split(' ');
        int[] spliti = new int[100];
        for (int i = 0; i < num; i++)
        {
            spliti[i] = int.Parse(split[i]);
        }
        return spliti;
    }

    public int[] Multiline_int(ref int datanum)
    {
        int i = 0;
        int[] data = new int[(int)Input.Define.MAX_ArraySize];
        while (true)
        {
            var input = Console.ReadLine();
            var value = int.Parse(input);
            if (value == 0) break;
            data[i] = value;
            i++;
        }
        datanum = i;
        return data;
    }

    /// <summary>
    /// ?????°??????int??????????????????????????????
    /// </summary>
    /// <param name="chr">???????????????</param>
    /// <param name="num">?????????????????????????????°</param>
    /// <param name="datanum">??????????????????????????°</param>
    /// <returns></returns>
    public int[,] Multiline_int(int chr, int num, ref int datanum)
    {
        int i = 0, zerocount = 0;
        int[,] data = new int[(int)Input.Define.MAX_ArraySize, (int)Input.Define.ArraySize2d];
        while (true)
        {
            var input = Console.ReadLine();
            var split = input.Split(' ');
            int[] spliti = new int[100];
            zerocount = 0;
            for (int j = 0; j < num; j++)
            {
                spliti[j] = int.Parse(split[j]);
                if (spliti[j] == 0) zerocount++;
            }
            if (zerocount == num) break;
            for (int j = 0; j < num; j++)
            {
                if (spliti[0] == 0 && spliti[1] == 0) break; // ???????????????????????????
            }
            for (int j = 0; j < num; j++)
            {
                data[i, j] = spliti[j];
            }
            i++;
        }
        datanum = i;
        return data;
    }

    /// <summary>
    /// ?????°??????int??????????????????????????????
    /// </summary>
    /// <param name="chr">???????????????</param>
    /// <param name="num">?????????????????????????????°</param>
    /// <param name="loadnum">???????????????????????°</param>
    /// <returns></returns>
    public int[,] Multiline_int(int chr, int num, int loadnum)
    {
        int i = 0;
        int[,] data = new int[(int)Input.Define.MAX_ArraySize, (int)Input.Define.ArraySize2d];
        while (true)
        {
            if (loadnum == i) break;

            var input = Console.ReadLine();
            var split = input.Split(' ');
            int[] spliti = new int[100];
            for (int j = 0; j < num; j++)
            {
                spliti[j] = int.Parse(split[j]);
            }
            for (int j = 0; j < num; j++)
            {
                data[i, j] = spliti[j];
            }
            i++;
        }
        return data;
    }


}

class EasyTask
{
    public void Swap(ref int a, ref int b)
    {
        int buf = 0;
        buf = a;
        a = b;
        b = buf;
    }






}

Measured memory_bytes: 9452