#include <iostream>
#include <vector>

#define INF 1e7

using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) cin >> a[i][j];
    }
    vector<vector<int>> p(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) cin >> p[i][j];
    }

    vector<vector<int>> dp(n, vector<int>(n, INF));
    dp[0][0] = p[0][0];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i > 0) {
                
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + p[i][j]);
            }
            if (j > 0) {
                dp[i][j] = min(dp[i][j], dp[i][j - 1] + p[i][j]);
            }
        }
    }
    cout << dp[n - 1][n - 1];
}