#include <bits/stdc++.h>

using namespace std;

int CardNumber[100];

int main() {
	int len, sum;
	string str;
	stringstream ss;

	while (1) {
		getline(cin, str);
		if (str.size() == 1 && str[0] == '0') {
			break;
		}
		memset(CardNumber, 0, sizeof(CardNumber));
		len = 0;
		ss << str;
		while (ss >> CardNumber[len]) {
			len++;
		}
		sort(CardNumber, CardNumber + len);

		/*cout << len << endl;
		for (int i = 0; i < len; i++) {
			cout << CardNumber[i] << ends;
		}
		cout << endl;*/

		sum = 0;
		for (int i = len - 1; i > -1; i--) {
			if (CardNumber[i] != 1) {
				sum += min(CardNumber[i], 10);
			}
			else {
				if (sum + i < 11) {
					sum += 11;
				}
				else {
					sum++;
				}
			}
		}

		sum = sum > 21 ? 0 : sum;
		cout << sum << endl;
		
		ss.clear();
		str = "";
	}

	return 0;
}
