function main(input) {
  const args = input.split("\n");
  let h, w;
  [h, w] = args[0].split(" ").map((x) => Number(x));

  let table = Array.from(new Array(h + 1), () => new Array(w + 1).fill(0));

  for (let y = 0; y < h; y++) {
    let tmp = args[y + 1].split(" ").map((x) => Number(x));
    let sum = 0;
    for (let x = 0; x <= w; x++) {
      if (x != w) {
        table[y][x] = tmp[x];
        sum += tmp[x];
      } else {
        table[y][x] = sum;
      }
    }
  }

  for (let x = 0; x <= w; x++) {
    let sum = 0;
    for (let y = 0; y < h; y++) {
      sum += table[y][x];
    }
    table[h][x] = sum;
  }

  for (let y = 0; y <= h; y++) {
    let output = "";
    for (let x = 0; x <= w; x++) {
      output += String(table[y][x]);
      if (x != w) {
        output += " ";
      }
    }
    console.log(output);
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
