#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string U[150], V; int T[200][100], cnt, cnt2[1000], x[100][100], large;
int main() {
	for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { T[i][j] = 114514; x[i][j] = 114514; } }
	while (cin >> U[cnt]) {
		U[cnt] += ','; 
		for (int i = 0; i < U[cnt].size(); i++) {
			if (U[cnt][i] == ',') {
				T[cnt][cnt2[cnt]] = stoi(V);
				V = "";
				cnt2[cnt]++;
			}
			else {
				V += U[cnt][i];
			}
		}
		cnt++;
	}
	large = cnt / 2; x[0][0] = T[0][0];
	for (int i = 0; i < cnt; i++) {
		for (int j = 0; j < cnt2[cnt]; j++) {
			if (i < large) {
				x[i + 1][j] = min(x[i + 1][j], x[i][j] + T[i + 1][j]);
				x[i + 1][j + 1] = min(x[i + 1][j + 1], x[i][j] + T[i + 1][j + 1]);
			}
			else {
				x[i + 1][j] = min(x[i + 1][j], x[i][j] + T[i + 1][j]);
				x[i + 1][j - 1] = min(x[i + 1][j - 1], x[i][j] + T[i + 1][j - 1]);
			}
		}
	}
	cout << x[cnt - 1][0] << endl;
	return 0;
}