#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int data[100];
  int dp[2][100] = {{0}};
  int *prev = dp[0], *next = dp[1];
  int idx = 0;
  int pdx = 0;
  while(true){
    int tmp;
    char c;
    if(scanf("%d",&tmp) == -1) break;
    data[idx++] = tmp;
    if(scanf("%c",&c) == -1) break;
    if(c != ','){
      if(pdx < idx){
	REP(i,idx){
	  next[i] = prev[i] + data[i];
	  if(i != 0) next[i] = max(next[i], prev[i-1] + data[i]);
	}
      }else{
	REP(i,idx){
	  next[i] = prev[i] + data[i];
	  next[i] = max(next[i], prev[i+1] + data[i]);
	}
      }

      //REP(i,idx) printf("%d ",next[i]); puts("");
      pdx = idx;
      idx = 0;
      swap(prev, next);
    }
  }

  printf("%d\n",prev[0]);
  return 0;
}