import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.TreeMap;
import java.math.BigDecimal;
import java.math.BigInteger;
    
public class Main{
 
static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE;
static final long LINF=Long.MAX_VALUE;
 
public static void main(String[] args) throws IOException{
InputReader ir=new InputReader(in);
int r=ir.nextInt();
int c=ir.nextInt();
int[][] table=new int[r][c];
for(int i=0;i<r;i++){
 for(int j=0;j<c;j++){
  table[i][j]=ir.nextInt();
 }
}
for(int i=0;i<r;i++){
 StringBuilder sb=new StringBuilder();
 int sum=0;
 for(int j=0;j<c;j++){
  sb.append(table[i][j]+" ");
  sum+=table[i][j];
 }
 sb.append(sum);
 out.println(sb);
}
int allsum=0;
StringBuilder sb=new StringBuilder();
for(int i=0;i<c;i++){
 int sum=0;
 for(int j=0;j<r;j++){
  sum+=table[j][i];
 }
 sb.append(sum+" ");
 allsum+=sum;
}
sb.append(allsum);
out.println(sb);
out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;
 
 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
  
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }
 
 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

 public boolean hasNext(){skip(); return hasNextByte();}
 
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public double nextDouble(){return Double.parseDouble(next());}
 
 public BigInteger nextBigInteger(){return new BigInteger(next());}
 
 public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 }
 
 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
}
} import java.io.InputStream; InputStream java.io import java.io.IOException; IOException java.io import java.io.PrintWriter; PrintWriter java.io import java.util.ArrayDeque; ArrayDeque java.util import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.BitSet; BitSet java.util import java.util.Comparator; Comparator java.util import java.util.Deque; Deque java.util import java.util.HashMap; HashMap java.util import java.util.HashSet; HashSet java.util import java.util.InputMismatchException; InputMismatchException java.util import java.util.Map; Map java.util import java.util.NoSuchElementException; NoSuchElementException java.util import java.util.PriorityQueue; PriorityQueue java.util import java.util.TreeMap; TreeMap java.util import java.math.BigDecimal; BigDecimal java.math import java.math.BigInteger; BigInteger java.math public class Main{
 
static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE;
static final long LINF=Long.MAX_VALUE;
 
public static void main(String[] args) throws IOException{
InputReader ir=new InputReader(in);
int r=ir.nextInt();
int c=ir.nextInt();
int[][] table=new int[r][c];
for(int i=0;i<r;i++){
 for(int j=0;j<c;j++){
  table[i][j]=ir.nextInt();
 }
}
for(int i=0;i<r;i++){
 StringBuilder sb=new StringBuilder();
 int sum=0;
 for(int j=0;j<c;j++){
  sb.append(table[i][j]+" ");
  sum+=table[i][j];
 }
 sb.append(sum);
 out.println(sb);
}
int allsum=0;
StringBuilder sb=new StringBuilder();
for(int i=0;i<c;i++){
 int sum=0;
 for(int j=0;j<r;j++){
  sum+=table[j][i];
 }
 sb.append(sum+" ");
 allsum+=sum;
}
sb.append(allsum);
out.println(sb);
out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;
 
 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
  
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }
 
 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

 public boolean hasNext(){skip(); return hasNextByte();}
 
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public double nextDouble(){return Double.parseDouble(next());}
 
 public BigInteger nextBigInteger(){return new BigInteger(next());}
 
 public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 }
 
 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
}
} Main static final InputStream in=System.in; in System.in System System.in static final PrintWriter out=new PrintWriter(System.out); out new PrintWriter(System.out) static final int INF=Integer.MAX_VALUE; INF Integer.MAX_VALUE Integer Integer.MAX_VALUE static final long LINF=Long.MAX_VALUE; LINF Long.MAX_VALUE Long Long.MAX_VALUE public static void main(String[] args) throws IOException{
InputReader ir=new InputReader(in);
int r=ir.nextInt();
int c=ir.nextInt();
int[][] table=new int[r][c];
for(int i=0;i<r;i++){
 for(int j=0;j<c;j++){
  table[i][j]=ir.nextInt();
 }
}
for(int i=0;i<r;i++){
 StringBuilder sb=new StringBuilder();
 int sum=0;
 for(int j=0;j<c;j++){
  sb.append(table[i][j]+" ");
  sum+=table[i][j];
 }
 sb.append(sum);
 out.println(sb);
}
int allsum=0;
StringBuilder sb=new StringBuilder();
for(int i=0;i<c;i++){
 int sum=0;
 for(int j=0;j<r;j++){
  sum+=table[j][i];
 }
 sb.append(sum+" ");
 allsum+=sum;
}
sb.append(allsum);
out.println(sb);
out.flush();
} main {
InputReader ir=new InputReader(in);
int r=ir.nextInt();
int c=ir.nextInt();
int[][] table=new int[r][c];
for(int i=0;i<r;i++){
 for(int j=0;j<c;j++){
  table[i][j]=ir.nextInt();
 }
}
for(int i=0;i<r;i++){
 StringBuilder sb=new StringBuilder();
 int sum=0;
 for(int j=0;j<c;j++){
  sb.append(table[i][j]+" ");
  sum+=table[i][j];
 }
 sb.append(sum);
 out.println(sb);
}
int allsum=0;
StringBuilder sb=new StringBuilder();
for(int i=0;i<c;i++){
 int sum=0;
 for(int j=0;j<r;j++){
  sum+=table[j][i];
 }
 sb.append(sum+" ");
 allsum+=sum;
}
sb.append(allsum);
out.println(sb);
out.flush();
} InputReader ir=new InputReader(in); ir new InputReader(in) int r=ir.nextInt(); r ir.nextInt() ir.nextInt ir int c=ir.nextInt(); c ir.nextInt() ir.nextInt ir int[][] table=new int[r][c]; table new int[r][c] r c for(int i=0;i<r;i++){
 for(int j=0;j<c;j++){
  table[i][j]=ir.nextInt();
 }
} int i=0; int i=0; i 0 i<r i r i++ i++ i {
 for(int j=0;j<c;j++){
  table[i][j]=ir.nextInt();
 }
} {
 for(int j=0;j<c;j++){
  table[i][j]=ir.nextInt();
 }
} for(int j=0;j<c;j++){
  table[i][j]=ir.nextInt();
 } int j=0; int j=0; j 0 j<c j c j++ j++ j {
  table[i][j]=ir.nextInt();
 } {
  table[i][j]=ir.nextInt();
 } table[i][j]=ir.nextInt() table[i][j] table[i] table i j ir.nextInt() ir.nextInt ir for(int i=0;i<r;i++){
 StringBuilder sb=new StringBuilder();
 int sum=0;
 for(int j=0;j<c;j++){
  sb.append(table[i][j]+" ");
  sum+=table[i][j];
 }
 sb.append(sum);
 out.println(sb);
} int i=0; int i=0; i 0 i<r i r i++ i++ i {
 StringBuilder sb=new StringBuilder();
 int sum=0;
 for(int j=0;j<c;j++){
  sb.append(table[i][j]+" ");
  sum+=table[i][j];
 }
 sb.append(sum);
 out.println(sb);
} {
 StringBuilder sb=new StringBuilder();
 int sum=0;
 for(int j=0;j<c;j++){
  sb.append(table[i][j]+" ");
  sum+=table[i][j];
 }
 sb.append(sum);
 out.println(sb);
} StringBuilder sb=new StringBuilder(); sb new StringBuilder() int sum=0; sum 0 for(int j=0;j<c;j++){
  sb.append(table[i][j]+" ");
  sum+=table[i][j];
 } int j=0; int j=0; j 0 j<c j c j++ j++ j {
  sb.append(table[i][j]+" ");
  sum+=table[i][j];
 } {
  sb.append(table[i][j]+" ");
  sum+=table[i][j];
 } sb.append(table[i][j]+" ") sb.append sb table[i][j]+" " table[i][j] table[i] table i j " " sum+=table[i][j] sum table[i][j] table[i] table i j sb.append(sum) sb.append sb sum out.println(sb) out.println out sb int allsum=0; allsum 0 StringBuilder sb=new StringBuilder(); sb new StringBuilder() for(int i=0;i<c;i++){
 int sum=0;
 for(int j=0;j<r;j++){
  sum+=table[j][i];
 }
 sb.append(sum+" ");
 allsum+=sum;
} int i=0; int i=0; i 0 i<c i c i++ i++ i {
 int sum=0;
 for(int j=0;j<r;j++){
  sum+=table[j][i];
 }
 sb.append(sum+" ");
 allsum+=sum;
} {
 int sum=0;
 for(int j=0;j<r;j++){
  sum+=table[j][i];
 }
 sb.append(sum+" ");
 allsum+=sum;
} int sum=0; sum 0 for(int j=0;j<r;j++){
  sum+=table[j][i];
 } int j=0; int j=0; j 0 j<r j r j++ j++ j {
  sum+=table[j][i];
 } {
  sum+=table[j][i];
 } sum+=table[j][i] sum table[j][i] table[j] table j i sb.append(sum+" ") sb.append sb sum+" " sum " " allsum+=sum allsum sum sb.append(allsum) sb.append sb allsum out.println(sb) out.println out sb out.flush() out.flush out String[] args args static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;
 
 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
  
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }
 
 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

 public boolean hasNext(){skip(); return hasNextByte();}
 
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public double nextDouble(){return Double.parseDouble(next());}
 
 public BigInteger nextBigInteger(){return new BigInteger(next());}
 
 public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 }
 
 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
} InputReader private InputStream in; in private byte[] buffer=new byte[1024]; buffer new byte[1024] 1024 private int curbuf; curbuf private int lenbuf; lenbuf public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;} InputReader {this.in=in; this.curbuf=this.lenbuf=0;} this.in=in this.in this this.in in this.curbuf=this.lenbuf=0 this.curbuf this this.curbuf this.lenbuf=0 this.lenbuf this this.lenbuf 0 InputStream in in public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 } hasNextByte {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 } if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  } curbuf>=lenbuf curbuf lenbuf {
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  } curbuf= 0 curbuf 0 try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   } catch(IOException e) {
    throw new InputMismatchException();
   } IOException e {
    throw new InputMismatchException();
   } throw new InputMismatchException(); new InputMismatchException() {
    lenbuf=in.read(buffer);
   } lenbuf=in.read(buffer) lenbuf in.read(buffer) in.read in buffer if(lenbuf<=0) return false; lenbuf<=0 lenbuf 0 return false; false return true; true private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;} readByte {if(hasNextByte()) return buffer[curbuf++]; else return -1;} if(hasNextByte()) return buffer[curbuf++]; else return -1; hasNextByte() hasNextByte return buffer[curbuf++]; buffer[curbuf++] buffer curbuf++ curbuf return -1; -1 1 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);} isSpaceChar {return !(c>=33&&c<=126);} return !(c>=33&&c<=126); !(c>=33&&c<=126) (c>=33&&c<=126) c>=33 c 33 c<=126 c 126 int c c private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;} skip {while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;} while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++; hasNextByte()&&isSpaceChar(buffer[curbuf]) hasNextByte() hasNextByte isSpaceChar(buffer[curbuf]) isSpaceChar buffer[curbuf] buffer curbuf curbuf++ curbuf public boolean hasNext(){skip(); return hasNextByte();} hasNext {skip(); return hasNextByte();} skip() skip return hasNextByte(); hasNextByte() hasNextByte public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 } next {
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 } if(!hasNext()) throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() StringBuilder sb=new StringBuilder(); sb new StringBuilder() int b=readByte(); b readByte() readByte while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  } !isSpaceChar(b) isSpaceChar(b) isSpaceChar b {
   sb.appendCodePoint(b);
   b=readByte();
  } sb.appendCodePoint(b) sb.appendCodePoint sb b b=readByte() b readByte() readByte return sb.toString(); sb.toString() sb.toString sb public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 } nextInt {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 } if(!hasNext()) throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() int c=readByte(); c readByte() readByte while (isSpaceChar(c)) c=readByte(); isSpaceChar(c) isSpaceChar c c=readByte() c readByte() readByte boolean minus=false; minus false if (c=='-') {
   minus=true;
   c=readByte();
  } c=='-' c '-' {
   minus=true;
   c=readByte();
  } minus=true minus true c=readByte() c readByte() readByte int res=0; res 0 do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c)); !isSpaceChar(c) isSpaceChar(c) isSpaceChar c {
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  } if(c<'0'||c>'9') throw new InputMismatchException(); c<'0'||c>'9' c<'0' c '0' c>'9' c '9' throw new InputMismatchException(); new InputMismatchException() res=res*10+c-'0' res res*10+c-'0' res*10+c res*10 res 10 c '0' c=readByte() c readByte() readByte return (minus)?-res:res; (minus)?-res:res (minus) -res res res public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 } nextLong {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 } if(!hasNext()) throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() int c=readByte(); c readByte() readByte while (isSpaceChar(c)) c=readByte(); isSpaceChar(c) isSpaceChar c c=readByte() c readByte() readByte boolean minus=false; minus false if (c=='-') {
   minus=true;
   c=readByte();
  } c=='-' c '-' {
   minus=true;
   c=readByte();
  } minus=true minus true c=readByte() c readByte() readByte long res = 0; res 0 do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c)); !isSpaceChar(c) isSpaceChar(c) isSpaceChar c {
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  } if(c<'0'||c>'9') throw new InputMismatchException(); c<'0'||c>'9' c<'0' c '0' c>'9' c '9' throw new InputMismatchException(); new InputMismatchException() res=res*10+c-'0' res res*10+c-'0' res*10+c res*10 res 10 c '0' c=readByte() c readByte() readByte return (minus)?-res:res; (minus)?-res:res (minus) -res res res public double nextDouble(){return Double.parseDouble(next());} nextDouble {return Double.parseDouble(next());} return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public BigInteger nextBigInteger(){return new BigInteger(next());} nextBigInteger {return new BigInteger(next());} return new BigInteger(next()); new BigInteger(next()) public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 } nextIntArray {
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 } int[] a=new int[n]; a new int[n] n for(int i=0;i<n;i++) a[i]=nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i a[i]=nextInt(); a[i]=nextInt() a[i] a i nextInt() nextInt return a; a int n n public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 } nextCharMap {
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 } char[][] map=new char[n][m]; map new char[n][m] n m for(int i=0;i<n;i++) map[i]=next().toCharArray(); int i=0; int i=0; i 0 i<n i n i++ i++ i map[i]=next().toCharArray(); map[i]=next().toCharArray() map[i] map i next().toCharArray() next().toCharArray next() next return map; map int n n int m m public class Main{
 
static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE;
static final long LINF=Long.MAX_VALUE;
 
public static void main(String[] args) throws IOException{
InputReader ir=new InputReader(in);
int r=ir.nextInt();
int c=ir.nextInt();
int[][] table=new int[r][c];
for(int i=0;i<r;i++){
 for(int j=0;j<c;j++){
  table[i][j]=ir.nextInt();
 }
}
for(int i=0;i<r;i++){
 StringBuilder sb=new StringBuilder();
 int sum=0;
 for(int j=0;j<c;j++){
  sb.append(table[i][j]+" ");
  sum+=table[i][j];
 }
 sb.append(sum);
 out.println(sb);
}
int allsum=0;
StringBuilder sb=new StringBuilder();
for(int i=0;i<c;i++){
 int sum=0;
 for(int j=0;j<r;j++){
  sum+=table[j][i];
 }
 sb.append(sum+" ");
 allsum+=sum;
}
sb.append(allsum);
out.println(sb);
out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;
 
 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
  
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }
 
 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

 public boolean hasNext(){skip(); return hasNextByte();}
 
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public double nextDouble(){return Double.parseDouble(next());}
 
 public BigInteger nextBigInteger(){return new BigInteger(next());}
 
 public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 }
 
 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
}
} public class Main{
 
static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE;
static final long LINF=Long.MAX_VALUE;
 
public static void main(String[] args) throws IOException{
InputReader ir=new InputReader(in);
int r=ir.nextInt();
int c=ir.nextInt();
int[][] table=new int[r][c];
for(int i=0;i<r;i++){
 for(int j=0;j<c;j++){
  table[i][j]=ir.nextInt();
 }
}
for(int i=0;i<r;i++){
 StringBuilder sb=new StringBuilder();
 int sum=0;
 for(int j=0;j<c;j++){
  sb.append(table[i][j]+" ");
  sum+=table[i][j];
 }
 sb.append(sum);
 out.println(sb);
}
int allsum=0;
StringBuilder sb=new StringBuilder();
for(int i=0;i<c;i++){
 int sum=0;
 for(int j=0;j<r;j++){
  sum+=table[j][i];
 }
 sb.append(sum+" ");
 allsum+=sum;
}
sb.append(allsum);
out.println(sb);
out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;
 
 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
  
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }
 
 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

 public boolean hasNext(){skip(); return hasNextByte();}
 
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public double nextDouble(){return Double.parseDouble(next());}
 
 public BigInteger nextBigInteger(){return new BigInteger(next());}
 
 public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 }
 
 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
}
} Main
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.TreeMap;
import java.math.BigDecimal;
import java.math.BigInteger;
    
public class Main{
 
static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE;
static final long LINF=Long.MAX_VALUE;
 
public static void main(String[] args) throws IOException{
InputReader ir=new InputReader(in);
int r=ir.nextInt();
int c=ir.nextInt();
int[][] table=new int[r][c];
for(int i=0;i<r;i++){
 for(int j=0;j<c;j++){
  table[i][j]=ir.nextInt();
 }
}
for(int i=0;i<r;i++){
 StringBuilder sb=new StringBuilder();
 int sum=0;
 for(int j=0;j<c;j++){
  sb.append(table[i][j]+" ");
  sum+=table[i][j];
 }
 sb.append(sum);
 out.println(sb);
}
int allsum=0;
StringBuilder sb=new StringBuilder();
for(int i=0;i<c;i++){
 int sum=0;
 for(int j=0;j<r;j++){
  sum+=table[j][i];
 }
 sb.append(sum+" ");
 allsum+=sum;
}
sb.append(allsum);
out.println(sb);
out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;
 
 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
  
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }
 
 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

 public boolean hasNext(){skip(); return hasNextByte();}
 
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public double nextDouble(){return Double.parseDouble(next());}
 
 public BigInteger nextBigInteger(){return new BigInteger(next());}
 
 public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 }
 
 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
}
}