#include<stdio.h>
#define N 200100
int f[N];
int a[N],n;
int main() {
int m,j,i,suma,sumb,sumc,sumd;
while(scanf("%d%d",&m,&n)!=EOF) {
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
scanf("%d",&f[(i-1)*n+j]);
for(i=1;i<=m;i++) {
suma=sumb=sumc=sumd=0;
for(j=1;j<=n;j++) {
sumd=sumc;
if(suma>sumb)
sumc=suma+f[(i-1)*n+j];
else
sumc=sumb+f[(i-1)*n+j];
suma=sumb;
sumb=sumd;
}
a[i]=sumc>sumb?sumc:sumb;
}
suma=sumb=sumc=sumd=0;
for(i=1;i<=m;i++) {
sumd=sumc;
if(suma>sumb)
sumc=suma+a[i];
else
sumc=sumb+a[i];
suma=sumb;
sumb=sumd;
}
printf("%d
",sumc>sumb?sumc:sumb);
}
return 0;
}