#include "bits/stdc++.h" using namespace std; #define int long long #define endl "\n" #define PII pair<int,int> #define PIII pair<int,PII> const int MOD = 1e9 + 7; const int N = 3e5; void slu() { int n, m; cin >> n >> m; vector<vector<PIII>> a(n + 1, vector<PIII >(m + 1, {0, {0, 0}})); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j].first; a[i][j].second.first += a[i][j - 1].second.first + a[i][j].first; a[i][j].second.second += a[i - 1][j].second.second + a[i][j].first; a[i][j].first = a[i][j].second.first + a[i][j].second.second - a[i][j].first + a[i - 1][j - 1].first; } } int dis = INT_MAX; int p2 = a[n][m].first; for (int i = 0; i <= n; i++) { int p1 = a[i][m].first; dis = min(dis, abs(p1 - (p2 - p1))); } for (int i = 0; i <= m; i++) { int p1 = a[n][i].first; dis = min(dis, abs(p1 - (p2 - p1))); } cout << dis; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T; // cin >> T; T = 1; while (T--)slu(); }