#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef pair<double,double> P;
typedef complex<double> CP;
typedef long long ll;


ll a[100];
string s;
ll b[100];
ll tmp[100];

int main(){
	int pas=0;
	rep(i,100){
		a[i]=0;
		b[i]=0;
	}
	while(getline(cin,s)){
		int cou=0;
		rep(i,100){
			tmp[i]=a[i];
		}
		rep(i,s.size()){
			if(s[i]<='9'&&s[i]>='0'){
				int sum=0;
				for(int j=i;j<s.size();j++){
					if(s[j]<='9'&&s[j]>='0'){
						sum*=10;
						sum+=s[j]-'0';
					}
					else break;
					i=j;
				}
				//cout<<sum<<" ";
				b[cou++]=sum;
			}
		}
		//cout<<endl;
		rep(i,cou){
			//cout<<b[i]<<" ";
		}
		//cout<<endl;
		if(cou>pas){
			rep(i,cou){
				if(i==0) a[0]+=b[0];
				else if(i==cou-1) a[i]+=b[i-1];
				else a[i]=max(tmp[i],tmp[i-1])+b[i];
			}
		}
		else{
			rep(i,cou){
				a[i]=max(tmp[i],tmp[i+1])+b[i];
			}
		}
		//cout<<endl;
		pas=cou;
	}
	cout<<a[0]<<endl;
	return 0;
}