#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
	string str = "";
	vector < vector <int> > hand;

	while (getline (cin, str ) ){
		if (str.length() == 1 && str[0] == '0'){
			break;
		} // end if

		int n;
		stringstream ss(str);
		vector <int> card;

		while (ss >> n){
			card.push_back (n );
		} // end while

		hand.push_back(card );

	} // end loop

	for (int i = 0; i < hand.size(); ++i){

		vector <int>::iterator it = hand[i].begin();
		int ace = 0;
		int sum = 0;

		for (; it != hand[i].end(); ++it ){
			if ((*it) == 1 ){
				++ace;
			}else if ((*it) >= 10){
				sum += 10;
			}else{
				sum += (*it);
			} // end if
		} // end for

		if (ace >= 4){
			sum += ace;
		}else if (ace == 3){
			if (sum == 0){
				sum = 21;
			}else{
				sum += 3;
			} // end if
		}else if (ace == 2){
			if (sum <= 9){
				sum += 12;
			}else{
				sum += 2;
			} // end if
		}else if (ace == 1){
			if (sum <= 10){
				sum += 11;
			}else{
				sum += 1;
			} // end if
		} // end if
		
		if (sum <= 21){
 			cout << sum << endl;
		}else{
			cout << '0' << endl;
		} // end if

	} // end for

	return 0;
}