#include <iostream>

using namespace std;

int main() {
  int r, c;
  int s[101][101] = {{0}};
  cin >> r >> c;
  for (int i = 0; i < r; ++i) {
    for (int j = 0; j < c; ++j) {
      cin >> s[i][j];
      s[i][c] += s[i][j];
      s[r][j] += s[i][j];
      s[r][c] += s[i][j];
    }
  }
  for (int i = 0; i < r + 1; ++i) {
    const char* sep = "";
    for (int j = 0; j < c + 1; ++j) {
      cout << sep << s[i][j];
      sep = " ";
    }
    cout << endl;
  }
  return 0;
} 

