#include <iostream>
#include<string>
// #include
using namespace std;
struct Node{ int value; int max;
};
bool judge(int* help,int num){ if(num == 0){ return false; } int min_ = help[0]; for(int i = 1;i<num ; i++){ if(help[i]>min_){ min_ = help[i]; }else{ return false; } } return true;
}
int getNumberSize(string s){ int size = s.size(); int i=0; int sum=0; while(i<size){ if(s[i] == ','){ sum++; } i++; } return sum+1;
}
int getsum(int* arr,int length){ int sum =0; for(int i =0;i<length;i++){ sum += arr[i]; } return sum;
}
int* getInnerNum(string s){ int sum = getNumberSize(s); int* arr = new int[sum]; char* ss = (char*)s.data(); const char* d = ","; char* p; p = strtok(ss,d); int i = 0; while(p){ arr[i] = atoi(p); p=strtok(NULL,d); i++; } return arr;
}
int func(string s) {
// 请完成函数功能
if(s.size() ==0){ return 0;
}
if(s.size()==1){ return 1;
}
int length = getNumberSize(s);
//得到了所有的数
int* arr = getInnerNum(s);
int sum = getsum(arr,length);
Node matrix[length][sum];
for(int i = 0;i<length;i++){ for(int j=0;j<=sum;j++){ matrix[i][j].value = -1; matrix[i][j].max = 0; }
}
int m= -1;
int first = arr[0];
matrix[0][0].value = 0;
matrix[0][0].max = 0;
matrix[0][first].value = 1;
matrix[0][first].max = first;
for(int i = 0;i< length-1;i++){ for(int j=0;j<=sum;j++){ if(matrix[i][j].value != -1){ //不要这个字 matrix[i+1][j].value = matrix[i][j].value; matrix[i+1][j].max = matrix[i][j].max; //要这个数,要判断是否是升序的 if(arr[i+1] >= matrix[i][j].max){ matrix[i+1][j+arr[i+1]].value = matrix[i][j].value+1; matrix[i+1][j+arr[i+1]].max = arr[i+1]; } } }
}
for(int i=0;i<=sum;i++){ if(matrix[length-1][i].value>m){ m = matrix[length-1][i].value; }
} return m;
}
int main() {
string s;
cin >> s;
cout << func(s) << endl;
return 0;
}