#include #include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } struct io_setup { io_setup() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); } } io_setup; using mint = atcoder::modint998244353; void solve() { int n, m; cin >> n >> m; atcoder::mcf_graph g(n * m + n * 2 + 2); int st = n * m + n * 2, ed = st + 1; vector> a(m, vector(n)); rep(i, 0, n) rep(j, 0, m) cin >> a[j][i]; ll shf = 1e9; rep(i, 0, n / 2) { g.add_edge(st, n * m + i, 1, 0); } rep(i, n / 2, n) { g.add_edge(n * m + n + i, ed, 1, 0); } rep(i, 0, m) { rep(j, 0, n - 1) { g.add_edge(i * n + j, i * n + j + 1, n, 0); } rep(j, 0, n) { g.add_edge(n * m + j, i * n + j, 1, a[i][j]); g.add_edge(i * n + j, n * m + n + j, 1, shf - a[i][j]); } } auto [fl, cs] = g.flow(st, ed); cout << fl * shf - cs << '\n'; } int main() { int t = 1; // cin >> t; while (t--) solve(); }