N,M=map(int,input().split()) l=[] inf=float("inf") dp=[[-inf]*(2) for i in range(N+1)] for i in range(N): tmp=map( int,input().split()) l.append(sum(tmp)) dp[0][0]=0 for i in range(N): for j in range(2): dp[i+1][j]=max(dp[i][j],dp[i+1][j]) dp[i+1][1]=max(dp[i+1][0]+l[i],dp[i+1][1]) dp[i+1][0]=max(dp[i][1]-l[i],dp[i+1][0]) print(dp[N][1])