#include <iostream>
#include <vector>
#include <string>
#include <limits>

using namespace std;

int cena(vector<vector<int>> matrica, int i, int j,int n){
    if(i==n-1 && j==n-1){
        return matrica[i][j];
    }
    else if(i==n || j==n){
        return INT_MAX;
    }
    else{
        return matrica[i][j] + min(cena(matrica,i+1,j,n),cena(matrica,i,j+1,n));
    }
    return INT_MAX;
}


int main()
{
    int n;
    cin>>n;
    vector<vector<int>> pustara;
    for(int i =0;i<n;i++){
        string red_matrice;
        cin>>red_matrice;
    }
    vector<vector<int>> matrica;
    for(int i =0;i<n;i++){
        vector<int> a;
        for (int j=0;j<n;j++){
            int b;
            cin>>b;
            a.push_back(b);
        }
        matrica.push_back(a);
    }
    cout<<cena(matrica,0,0,n);

}