import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;

		int count = 0;
		int r = 0;
		int c = 0;
		int[][] sheet = null;
		try {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				if (count == 0) {
					r = Integer.valueOf(strings[0]);
					c = Integer.valueOf(strings[1]);
					sheet = new int[r + 1][c + 1];
				}
				else if (count <= r) {
					for (int i = 0; i < c; i++) {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					}
				}
				if (count == r) {
					for (int w = 0; w < c; w++) {
						int sum = 0;
						for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						}
						sheet[r][w] = sum;
					}

					for (int h = 0; h < r + 1; h++) {
						int sum = 0;
						for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						}
					}

				}

				count++;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}


/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