#include <iostream>
using namespace std;
int main(){
  int h,w;cin>>h>>w;
  int mp[h][w];
  for(int i = 0; h > i; i++){
    int sm = 0;
    for(int j = 0; w > j; j++){
      cin>>mp[i][j];sm+=mp[i][j];
      cout << mp[i][j] << " ";
    }
    cout << sm << endl;
  }
  int ret = 0;
  for(int i = 0; w > i; i++){
    int sm = 0;
    for(int j = 0; h > j; j++){
      sm += mp[j][i];
    }
    ret += sm;
    cout << sm << " ";
  }
  cout << ret << endl;
}
