#include<bits/stdc++.h>
using namespace std;
int dp[105][105];
int main(){
memset(dp,0x3f,sizeof dp);
int n;
cin >> n;
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= n;j ++){
int x;
cin >> x;
if(i == 1 and j == 1){
dp[i][j] = x;
continue;
}
dp[i][j] = min(dp[i - 1][j],dp[i][j - 1]) + x;
}
}
cout << dp[n][n];
return 0;
}