#include <bits/stdc++.h>

using namespace std;


int uktoks(int i, int j, vector<vector<int>> vtoks) {
    int n = vtoks.size();
    int toks[n][n];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            toks[i][j] = vtoks[i][j];
        }
    }
    if (i == 0 && j == 0) return toks[i][j];
    else if (i == 0) return uktoks(i, j - 1, vtoks) + toks[i][j];
    else if (j == 0) return uktoks(i - 1, j, vtoks) + toks[i][j];
    return min(uktoks(i - 1, j, vtoks), uktoks(i, j - 1, vtoks)) + toks[i][j];
}

int main()
{
    int n;
    cin >> n;
    char polja[n][n];
    int toks[n][n];
    for (int i = 0; i < n; i++) {
        string a;
        for (int j = 0; j < n; j++) {
            cin >> polja[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) cin >> toks[i][j];
    }

    vector<vector<int>> vtoks;
    for (int i = 0; i < n; i++) {
        vector<int> temp;
        for (int j = 0; j < n; j++) {
            temp.push_back(toks[i][j]);
        }
        vtoks.push_back(temp);
    }
    cout << uktoks(n - 1, n - 1, vtoks);



    return 0;
}