#include #include #include #include #include #include #include using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(int)(n); i++) const i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<998244353>; int main(){ int N, M; cin >> N >> M; vector dp(M, 0); vector A(M, 0); rep(i,N){ rep(j,M) cin >> A[j]; rep(j,M) dp[j] += A[j]; i64 mdp = *min_element(dp.begin(), dp.end()); rep(j,M) dp[j] = min(dp[j], mdp + A[j]); } i64 ans = *min_element(dp.begin(), dp.end()); if(N == 1) ans = 0; cout << ans << '\n'; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;