#include <iostream>
#include <string>
#include <sstream>
using namespace std;

const int SIZE = 50;

int main(){
	char c;
	string s;
	int n, max = 0;
	int* table = new int[ SIZE + 1 ]();

	while ( cin >> s ){
		int* input = new int[ SIZE + 1 ]();
		bool isInt = true;
		int cnt = 0;
		istringstream is( s );

		while ( !is.eof() ){
			if ( isInt ){
				is >> n;
				input[ ++cnt ] = n;
			}else{
				is >> c;
			}
			isInt = !isInt;
		}
		if ( cnt > max ){
			max = cnt;
		}

		for ( int i = 0, p = max; i < cnt; ++i, --p ){
			table [ p ] = input[ cnt - i ] + ( table[ p - 1 ] > table[ p ] ? table[ p - 1 ] : table[ p ] );
			
		}

		if ( cnt == 1 ){
			isEnd = !isEnd;
		}

		delete[] input;
	}

	cout << table[ max ] << endl;

	delete[] table;
	return 0;
}