#include <iostream>
#include <deque>
#include <cstdio>
#include <queue>
using namespace std;
typedef pair<int,pair<int,int> > NODE;
#define SUM first
#define Y second.first
#define X second.second
#define ppp(a,b,c) make_pair(a,make_pair(b,c))
int main(){
	int a;char b;
	int u = 0;
	int mx = 0;
	int ret = 0;
	int done[100][100];
	for(int i=0;i<100;i++)
	for(int j=0;j<100;j++)
	done[i][j] = -1;
	vector< deque<int> > data(1);
	while(~scanf("%d%c",&a,&b)){
		if(b == ','){
			data[u].push_back(a);
		}else{
			data[u].push_back(a);
			mx = max<int>(data[u].size(),mx);
			if(data[u].size()<mx){
				int tmp = data[u].size();
				for(int i=0;i<mx-tmp;i++){
					data[u].push_front(-1);
					data[u].push_back(-1);
				}
			}
			u++;
			data.resize(data.size()+1);
		}
	}
	/*for(int i=0;i<data.size();i++){
	for(int j=0;j<data[i].size();j++){
		printf("%3d",data[i][j]);
	}
	cout << endl;
	}
	*/
	queue<NODE> Q;
	Q.push(ppp(data[0][0],0,0));
	while(Q.size()){
		NODE q = Q.front();Q.pop();
		if(q.SUM <= done[q.Y][q.X]){
			continue;
		}else{
			done[q.Y][q.X] = q.SUM;
		}
		if(data[q.Y+1].empty()){
			ret = max(ret,q.SUM);
			continue;
		}
		if(~data[q.Y+1][q.X])Q.push(ppp(q.SUM+data[q.Y+1][q.X],  q.Y+1,q.X  ));
		if(~data[q.Y+1][q.X+1])Q.push(ppp(q.SUM+data[q.Y+1][q.X+1],q.Y+1,q.X+1));
	}
	/*for(int i=0;i<data.size();i++){
	for(int j=0;j<data[i].size();j++){
		printf("%3d",done[i][j]);
	}
	cout << endl;
	}*/
	cout << ret << endl;
		
}