#include #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--) #define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++) #define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--) #define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++) #define ALL(x) x.begin(), x.end() using ll = long long; using namespace std; int main(){ int n, m; cin >> n >> m; vector a(n, 0); rep(i, n)rep(j, m){ ll in; cin >> in; a.at(i) += in; } a.push_back(LLONG_MAX); ll ans = 0; rep(i, n){ ll add = a.at(i); bool mode = false; ll bf = -1; rep2(j, i+1, n){ if(mode == false){ if(a.at(j) < a.at(j+1)){ bf = a.at(j); mode = true; } }else{ if(a.at(j) > a.at(j+1)){ add += a.at(j) - bf; mode = false; } } } ans = max(ans, add); } cout << ans << endl; return 0; }