#include<cstdio>
int main(void){int r,c,e[101][101]={0},i,j;scanf("%d%d",&r,&c);for(i=0;i<r;++i){for(j=0;j<c;++j){scanf("%d",&e[i][j]);}}for(i=0;i<r;++i){for(j=0;j<c;++j){e[i][c]+=e[i][j];e[r][j]+=e[i][j];}e[r][c]+=e[i][c];}for(i=0;i<r+1;++i){for(j=0;j<c+1;++j){printf("%d",e[i][j]);if(j!=c){printf(" ");}}puts("");}return(0);}

