#include<cstdlib>
#include<iostream>
#include<vector>
using namespace std;
int vec[110][110];
int ans = 0,st,Index=0,Index2=0;
const int INF = 1<<29;
void rec(int s,int sum,int counter){
  if(counter == Index){
    ans = max(ans,sum);
    return;
  }
  if(vec[s+1][s] != INF){
    rec(s,sum+vec[s+1][s],counter+1);
  }
  if(vec[s+1][s+1] != INF){
    rec(s+1,sum+vec[s+1][s+1],counter+1);
  }
}
int main(){
  string s;
  
  for(int i=109;i>=0;i--)for(int j=0;j<110;j++)vec[j][i] = INF;
  while(cin >> s){
    Index2=0;
    st = 0;
    for(int i=0;i<=s.length();i++){
      if(s[i] == ',' || i == s.length()){
	vec[Index][Index2] = (atoi)(s.substr(st,i-st).c_str() );
	st = i+1;
	Index2++;
      }
    }
    Index++;
  }
  rec(0,vec[0][0],0);
  cout << ans << endl;
  return 0;
}