#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
vector<int>x;
int main(){
	string s;
	while(getline(std::cin,s)){
		int i;
		for(i=0;i<s.size();i++)if (s[i]==',')s[i]=' ';
		stringstream ss(s);
		vector<int>A,B;
		while(ss>>i)A.push_back(i);
		if(x.size()<A.size()){
			x.insert(x.begin(),1,0);
			x.push_back(0);
		}
		for(i=0;i<A.size();i++)B.push_back((x[i]>x[i+1]?x[i]:x[i+1])+A[i]);
		x=B;
	}
	cout<<x[0]<<endl;
}