#include<bits/stdc++.h>
using namespace std;
int64_t INF = INT_MAX;
int main(){
    int64_t n;
    cin>>n;
    vector<vector<int64_t>> v(n, vector<int64_t>(n));
    int64_t 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<int64_t>, vector<vector<int64_t>>, greater<vector<int64_t>>> pq;
    pq.push({v[0][0], 0, 0});
    vector<vector<int64_t>> dijkstra(n, vector<int64_t>(n, INF));
    vector<vector<bool>> bio(n, vector<bool>(n, false));
    while(!pq.empty()){
        int64_t price = pq.top()[0];
        int64_t row = pq.top()[1];
        int64_t 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;
}