#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	while (true) {
		string str;
		getline(cin, str);
		int n = count(str.c_str(), str.c_str() + str.size(), ' ') + 1;
		vector<int> card(n);
		stringstream ss(str);
		REP(i, n) ss >> card[i];
		if (card[0] == 0) break;
		
		sort(card.begin(), card.end());
		int c = count(card.begin(), card.end(), 1);
		
		int score = 0;
		FOR(i, c, n) {
			if (card[i] > 10) score += 10;
			else score += card[i];
		}
		
		while (c--) {
			if (score + 11 > 21)
				score += 1;
			else if (abs(21 - (score + 1)) > abs(21 - (score + 11))) {
				if (score + 11 <= 21 - c)
					score += 11;
				else
					score += 1;
			}
			else
				score += 1;
		}
		if (score > 21) score = 0;
		
		cout << score << endl;
	}
	return 0;
}