#include <bits/stdc++.h>
using namespace std;
long long n, mat1[1005][1005], mat2[1005][1005],dp[1005][1005];
int main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    cin>>n;
    memset(mat1, 1000005, sizeof(mat1));
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cin>>mat2[i][j];
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cin>>mat1[i][j];
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            dp[i][j] += min(mat1[i-1][j], mat1[i][j-1]) + mat1[i][j];
            dp[1][1] = mat1[1][1];
        }
    }
    cout<<dp[n][n];
return 0;
}