#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n; cin >> n;
    vector<string> kompleks(n);
    for (int i = 0; i < n; i++) {
        cin >> kompleks[i];
    }

    vector<vector<long long>> tabla(n, vector<long long>(n));

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> tabla[i][j];
        }
    }

    vector<vector<long long>> dp(n, vector<long long>(n));
    dp[0][0] = tabla[0][0];

    for (int i = 1; i < n; i++) {
        dp[0][i] = dp[0][i - 1] + tabla[0][i];
    }
    for (int i = 1; i < n; i++) {
        dp[i][0] = dp[i-1][0] + tabla[i][0];
    }

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

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

    return 0;
}