#include <bits/stdc++.h>
using namespace std;
#define MAX 100

int table[MAX][MAX];
int csum[MAX];

int main(){
	int r, c;
	
	cin >> r >> c;
	
	for(int i=0; i<r; i++){
		int sum = 0;
		for(int j=0; j<c; j++){
			int cell;
			cin >> cell;
			sum += cell;
			csum[j] += cell;
			cout << cell << " ";
		}
		cout << sum << "\n";
	}
	
	int sum = 0;
	for(int j=0; j<c; j++){
		cout << csum[j] << " ";
		sum += csum[j];
	}
	cout << sum << endl;
	return 0;
}
