// Online C++ compiler to run C++ program online
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main() {
string str;
cin >> str;
//逗号分割
vector<int> v;
str += ",";
while (str.find(",") != string::npos) {
int found = str.find(",");
v.push_back(atoi(str.substr(0, found).c_str()));
str = str.substr(found + 1);
}
int maxWeight;
cin >> maxWeight;
//排序
sort(v.begin(), v.end());
int res = 0;
int val = 0;
for (auto x : v) {
if ((val + x) > maxWeight)
{
break;
}
val += x;
++res;
}
cout << res << endl;
return 0;
}