#include <iostream>
#include <bits/stdc++.h>

using namespace std;

#define endl "\n"
#define ll long long

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

    int n;
    cin >> n;
    string s;
    int mat[n][n];
    int dp[n][n] = {0};

    for(int i=0; i<n; i++){
        cin >> s;
    }

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

    dp[0][0] = mat[0][0];

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

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

    /*
    cout << endl;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            cout << dp[i][j] << " ";;
        }
        cout << endl;
    }
    */

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

}