import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;

void main() {
	int [] dp = new int[101];
	dp[] = 0;
	long n;
	while(!stdin.eof()) {
		auto s = readln().replace(",", " ").split();
		if(!s.empty()){
			int [] newdp;
			int offset;
			if(n < s.length) {
				offset = 1;
			} else {
				offset = 2;
			}
			n = s.length;
			newdp ~= 0;
			for(int i = 0; i < s.length; ++i) {
				newdp ~= max(dp[i+offset], dp[i-1+offset])+to!int(s[i]);
			}
			newdp ~= 0;
			dp = newdp;
		}
	}
	writeln(dp[1]);
}