#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int n; cin >> n;
    vector<vector<int>> a(n), dp(n);
    for (int i = 0; i < n; i++) {
        vector<int> red(n), prazan(n);
        for (int j = 0; j < n; j++) {
            cin >> red[j];
            if (i == 0) {
                if (j > 0) prazan[j] = prazan[j - 1] + red[j];
                else prazan[j] = red[j];
            }

            if (j == 0) {
                if (i > 0) prazan[j] = dp[i - 1][j] + red[j];
                else prazan[j] = red[j];
            }
        }
        dp[i] = prazan;
        a[i] = red;
    }

    for (int i = 1; i < n; i++) {
        for (int j = 1; j < n; j++) {
            dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + a[i][j];
        }
    }

    cout << dp[n - 1][n - 1] << endl;

    return 0;
}