#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define inf 0x3f3f3f3f
#define N 2200
using namespace std;
inline char gc(){
static char now[1<<16],*S,*T;
if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
return *S++;
}
inline int read(){
int x=0;char ch=gc();
while(ch<'0'||ch>'9') ch=gc();
while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}
return x;
}
struct node{
int x,y,z,c,next;
}data[N<<1];
int f[N],m,n,pre[N],path[N],num,h[N],T,mp[50][50],nm[50][50];bool flag[N];
inline void insert1(int x,int y,int z,int c){
data[++num].y=y;data[num].z=z;data[num].c=c;data[num].next=h[x];h[x]=num;data[num].x=x;
data[++num].y=x;data[num].z=0;data[num].c=-c;data[num].next=h[y];h[y]=num;data[num].x=y;
}
inline int calc(int i,int j){return (m+m+(i-2))*(i-1)/2+j;}
inline bool spfa(){
queue<int>q;memset(flag,0,sizeof(flag));memset(f,128,sizeof(f));f[0]=0;flag[0]=1;q.push(0);memset(pre,-1,sizeof(pre));
while(!q.empty()){
int x=q.front();q.pop();flag[x]=0;
for (int i=h[x];i;i=data[i].next){
int y=data[i].y,z=data[i].z,c=data[i].c;
if (f[x]+c>f[y]&&z){
f[y]=f[x]+c;pre[y]=x;path[y]=i;
if(!flag[y]) flag[y]=1,q.push(y);
}
}
}if (pre[T]==-1) return 0;else return 1;
}
int main(){
freopen("loj.in","r",stdin);
m=read();n=read();int len=m,top=m,down=m+n-1,nn=(top+down)*n/2;T=nn*2+1;
for (int i=1;i<=n;++i){
for (int j=1;j<=len;++j) mp[i][j]=read(),nm[i][j]=calc(i,j);len++;
}len=m;num=1;T=nn*2+1;
for (int i=1;i<=n;++i){
for (int j=1;j<=len;++j) {
if (i==1)insert1(0,nm[i][j],1,0);insert1(nm[i][j],nm[i][j]+nn,1,mp[i][j]);
if (i!=n){
insert1(nm[i][j]+nn,nm[i+1][j],1,0);insert1(nm[i][j]+nn,nm[i+1][j+1],1,0);
}else{
insert1(nm[i][j]+nn,T,1,0);
}
}len++;
}int ans=0;
//for (int i=2;i<=num;++i) if (data[i].c>0)printf("%d %d %d %d\n",data[i].x,data[i].y,data[i].z,data[i].c);
while(spfa()){
int now=T,minn=inf;
while(now) {minn=min(minn,data[path[now]].z);now=pre[now];}now=T;
while(now){ans+=minn*data[path[now]].c;data[path[now]].z-=minn;data[path[now]^1].z+=minn;now=pre[now];}
}printf("%d\n",ans);ans=0;memset(h,0,sizeof(h));len=m;num=1;
for (int i=1;i<=n;++i){
for (int j=1;j<=len;++j) {
if (i==1)insert1(0,nm[i][j],1,0);insert1(nm[i][j],nm[i][j]+nn,inf,mp[i][j]);
if (i!=n){
insert1(nm[i][j]+nn,nm[i+1][j],1,0);insert1(nm[i][j]+nn,nm[i+1][j+1],1,0);
}else{
insert1(nm[i][j]+nn,T,inf,0);
}
}len++;
}
while(spfa()){
int now=T,minn=inf;
while(now) {minn=min(minn,data[path[now]].z);now=pre[now];}now=T;
while(now){ans+=minn*data[path[now]].c;data[path[now]].z-=minn;data[path[now]^1].z+=minn;now=pre[now];}
}printf("%d\n",ans);ans=0;memset(h,0,sizeof(h));len=m;num=1;
for (int i=1;i<=n;++i){
for (int j=1;j<=len;++j) {
if (i==1)insert1(0,nm[i][j],1,0);insert1(nm[i][j],nm[i][j]+nn,inf,mp[i][j]);
if (i!=n){
insert1(nm[i][j]+nn,nm[i+1][j],inf,0);insert1(nm[i][j]+nn,nm[i+1][j+1],inf,0);
}else{
insert1(nm[i][j]+nn,T,inf,0);
}
}len++;
}
while(spfa()){
int now=T,minn=inf;
while(now) {minn=min(minn,data[path[now]].z);now=pre[now];}now=T;
while(now){ans+=minn*data[path[now]].c;data[path[now]].z-=minn;data[path[now]^1].z+=minn;now=pre[now];}
}printf("%d",ans);
return 0;
}