#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 vtoks[i][j];
    else if (i == 0) return uktoks(i, j - 1, vtoks) + vtoks[i][j];
    else if (j == 0) return uktoks(i - 1, j, vtoks) + vtoks[i][j];
    return min(uktoks(i - 1, j, vtoks), uktoks(i, j - 1, vtoks)) + vtoks[i][j];
}

int main()
{
    int n;
    cin >> n;
    char polja[n][n];
    int toks[n][n];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> polja[i][j];
        }
    }
    int a;
    vector<vector<int>> vtoks;
    vector<int> temp;
    for (int i = 0; i < n; i++) {
        temp = {};
        for (int j = 0; j < n; j++) {
                cin >> a;
                temp.push_back(a);
        }
        vtoks.push_back(temp);
    }

    /*
    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;
}