#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
int minimumTotal(vector<vector<int>>& triangle);
int main()
{
int m=0;
cin>>m;
vector<vector<int> > triangle;
int value;
vector<int> temp;
for(int i=0;i<m;i++)
{
for(int j=0;j<=i;j++)
{
cin>>value;
temp.push_back(value);
}
triangle.push_back(temp);
temp.clear();
}
cout<<minimumTotal(triangle)<<endl;
return 0;
}
int minimumTotal(vector<vector<int>>& triangle)
{
int length = triangle.size();
long record[length];
record[0] = triangle[0][0];
for(int i=1;i<length;i++)
{
long temp_left = record[0];
record[0] += triangle[i][0];
for(int j=1;j<i;j++)
{
long temp_right = record[j];
record[j] = min(temp_left,temp_right)+triangle[i][j];
temp_left = temp_right;
}
record[i] = temp_left + triangle[i][i];
}
long min_sum = record[0];
for(int i=1;i<length;i++)
{
if(record[i]<min_sum)
{
min_sum = record[i];
}
}
return min_sum;
}