#include<iostream> #include<algorithm> #define maxn 1010 #define ll long long usingnamespacestd;
int n, m, a[maxn][maxn];
ll f[maxn][maxn];
voidwork(){ cin >> n >> m; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) cin >> a[i][j]; for (int i = 1; i <= n; ++i) for (int j = m; j; --j) { f[i][j] = a[i][j]; if (i > 1) f[i][j] = max(f[i][j], f[i - 1][j]); if (j < m) f[i][j] = max(f[i][j], f[i][j + 1]); if (i > 1 && j < m) f[i][j] = max(f[i][j], f[i - 1][j + 1] + a[i][j]); } cout << f[n][1] << "\n"; }