#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
vector<int>input(string s) {
	vector<int>ret;
	int k = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == ' ') {
			ret.push_back(min(k, 10));
			k = 0;
		}
		else {
			k *= 10;
			if (s[i] == '1')k += 1;
			else if (s[i] == '2')k += 2;
			else if (s[i] == '3')k += 3;
			else if (s[i] == '4')k += 4;
			else if (s[i] == '5')k += 5;
			else if (s[i] == '6')k += 6;
			else if (s[i] == '7')k += 7;
			else if (s[i] == '8')k += 8;
			else if (s[i] == '9')k += 9;
			else if (s[i] == '0')k += 0;
		}
	}
	ret.push_back(min(k, 10));
	return ret;
}
int main() {
	string s;
	while (getline(cin, s)) {
		if (s == "0")return 0;
		vector<int>v = input(s);
		int cnt1 = 0;
		int cnt = 0;
		for (int i = 0; i < v.size(); i++) {
			if (v[i] == 1)cnt1++;
			else cnt += v[i];
		}
		int ans = 0;
		cnt += cnt1;
		if (cnt <= 21)ans = cnt;
		for (int i = 0; i < cnt1; i++) {
			cnt += 10;
			if (cnt <= 21)ans = max(ans, cnt);
		}
		cout << ans << endl;
	}
}