#include<bits/stdc++.h>
using namespace std;
int INF = INT_MAX;
int main(){
    int n;
    cin>>n;
    vector<vector<int>> v(n, vector<int>(n));
    int x;
    for(int i=0;i<n;i++) cin>>x;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>v[i][j];
        }
    }
    priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> pq;
    pq.push({v[0][0], 0, 0});
    vector<vector<int>> dijkstra(n, vector<int>(n, INF));
    vector<vector<bool>> bio(n, vector<bool>(n, false));
    while(!pq.empty()){
        int price = pq.top()[0];
        int row = pq.top()[1];
        int col = pq.top()[2];
        pq.pop();
        dijkstra[row][col] = min(dijkstra[row][col], price);
        if(col!=n-1){
            if(!bio[row][col+1])
                pq.push({dijkstra[row][col] + v[row][col+1], row, col+1});
        }
        if(row!=n-1){
            if(!bio[row+1][col])
                pq.push({dijkstra[row][col] + v[row+1][col], row+1, col});
        }
        bio[row][col] = true;
    }
    cout<<dijkstra[n-1][n-1]<<endl;
}