#include<iostream>
#include<vector>
#include<queue>

using namespace std;

#define EMAX 25

struct S{
	int e, num;
};

int main(){

	vector<int> V[EMAX];
	int E[EMAX];
	int max = -1;
	char gav;
	queue<S> qu;
	S t, n;

	V[0].push_back(1); V[0].push_back(1);
	V[1].push_back(3); V[1].push_back(4);
	V[2].push_back(4); V[2].push_back(5);
	V[3].push_back(6); V[3].push_back(7);
	V[4].push_back(7); V[4].push_back(8);
	V[5].push_back(8); V[5].push_back(9);
	V[6].push_back(10); V[6].push_back(11);
	V[7].push_back(11); V[7].push_back(12);
	V[8].push_back(12); V[8].push_back(13);
	V[9].push_back(13); V[9].push_back(14);
	V[10].push_back(15);
	V[11].push_back(15); V[11].push_back(16);
	V[12].push_back(16); V[12].push_back(17);
	V[13].push_back(17); V[13].push_back(18);
	V[14].push_back(18);
	V[15].push_back(19);
	V[16].push_back(19); V[16].push_back(20);
	V[17].push_back(20); V[17].push_back(21);
	V[18].push_back(21);
	V[19].push_back(22);
	V[20].push_back(22); V[20].push_back(23);
	V[21].push_back(23);
	V[22].push_back(24);
	V[23].push_back(24);

	cin >> E[0];
	cin >> E[1] >> gav >> E[2];
	cin >> E[3] >> gav >> E[4] >> gav >> E[5];
	cin >> E[6] >> gav >> E[7] >> gav >> E[8] >> gav >> E[9];
	cin >> E[10] >> gav >> E[11] >> gav >> E[12] >> gav >> E[13] >> gav >> E[14];
	cin >> E[15] >> gav >> E[16] >> gav >> E[17] >> gav >> E[18];
	cin >> E[19] >> gav >> E[20] >> gav >> E[21];
	cin >> E[22] >> gav >> E[23];
	cin >> E[24];

	t.e = 0, t.num = E[0];
	qu.push(t);
	while (!qu.empty()){
		n = qu.front();
		qu.pop();
		if (n.e == 24){
			if (n.num > max) max = n.num;
			continue;
		}
		for (int i = 0; i < V[n.e].size(); i++){
			t.e = V[n.e][i];
			t.num = n.num + E[n.e];
			qu.push(t);
		}
	}

	cout << max << endl;

	return 0;
}