#include using namespace std; using ll = long long; int main () { int N, M; cin >> N >> M; ll dp[1010]; for (int i = 0; i < M; i ++) { cin >> dp[i]; } ll A[1010]; for (int i = 0; i < N-1; i ++) { ll mini = (ll)1e18; for (int j = 0; j < M; j ++) { cin >> A[j]; mini = min(mini, dp[j] + A[j]); } for (int j = 0; j < M; j ++) { dp[j] = min(mini, dp[j]) + A[j]; } } ll ans = (ll)1e18; for (int i = 0; i < M; i ++) { ans = min(ans, dp[i]); } cout << ans << endl; }