#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];
        }
    }
    cout << i << " " << j << " - " << toks[i][j] << "\n";
    if (i == 0 && j == 0) return 0;
    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;
}








/*
    int n;
    cin >> n;

    vector<int> a;
    vector<int> b;



    for (int i = 0; i < 2 * n; i++) {
        if (i < n) {
            if (i % 2 == 0) a.push_back(i / 2 + 1);
            else a.push_back(2 * n - (i / 2));
        }
        else {
            if (i % 2 == 0) b.push_back(i / 2 + 1);
            else b.push_back(2 * n - (i / 2));
        }
    }


    for (int i = 0; i < n; i++) cout << a[i] << " ";
    cout << "\n";
    for (int i = 0; i < n; i++) cout << b[i] << " ";
    */