/*
简单的求最短路问题。
告诉你一个对称矩阵。
对角线元素全部为零(矩阵中没有给出对角线元素)
x表示两点不可达
求起始点1到其他顶点的最短距离的最大值
这里我用的是spfa
*/
#include<iostream>
#include<string>
#include<stack>
#include<stdio.h>
using namespace std;
const int N = 110;
const int inf = 0x3f3f3f3f;
int Graph[110][110];
bool vis[N];
int dis[N];
int n;
int outstack[N];
int atot(string a)
{
int ans = 0;
for(int i = 0 ; i < a.length() ; i++)
{
ans *= 10;
ans += a[i]-'0';
}
return ans;
}
bool spfa(int start)
{
for(int i = 0 ; i < n ; i++)
{
dis[i] = inf;
outstack[i] = 0;
vis[i] = false;
}
stack<int>s;
s.push(start);
vis[start] = true;
dis[start] = 0;
while(!s.empty())
{
int cur = s.top();
s.pop();
outstack[cur]++;
if(outstack[cur] > n)
{
return false;
}
for(int i = 0 ; i < n ; i++)
{
if(dis[i] > dis[cur] + Graph[cur][i])
{
dis[i] = dis[cur] + Graph[cur][i];
if(!vis[i])
{
vis[i] = true;
s.push(i);
}
}
}
vis[cur] = false;
}
return true;
}
int main()
{
while(scanf("%d",&n) != EOF)
{
for(int i = 0 ; i < n ; i++)
{
for(int j = 0 ; j < n ; j++)
{
if(i == j)
{
Graph[i][j] = 0 ;
}
else
{
Graph[i][j] = inf;
}
}
}
string str;
for(int i = 1 ; i < n ; i++)
{
for(int j = 0 ; j < i ; j++)
{
cin>>str;
if(str[0] != 'x')
{
Graph[i][j] = Graph[j][i] = atot(str);
}
}
}
bool flag = spfa(0);
if(flag)
{
int maxn = -1;
for(int i = 0 ; i < n ; i++)
{
if(maxn < dis[i])
{
maxn = dis[i];
}
}
printf("%d\n",maxn);
}
}
return 0;
}