#include <iostream>
#include <vector>
#include <algorithm>	
#include <numeric>
#include <sstream>

#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;


int main()
{
	string str = "";
	
	while (getline (cin, str ) && str != "0" ){
		stringstream ss (str );
		vector <int> hand;
		int n;
		int ace = 0;
		while (ss >> n ){
			if (n == 1 )
				ace++;
			if (n > 10 )
				n = 10;
			hand.push_back (n );
		} // end while
		int sum = accumulate (ALL (hand ), 0 );
		int res = 0;
		if (ace == 0 && sum > 21 ){
			res = 0;
		}else if (ace == 0 && sum <= 21 ){
			res = sum;
		}else if (ace && sum > 21 ){
			res = 0;
		}else if (ace && sum == 21 ){
			res = sum;
		}else{
			res = sum;
			for (int i = 1; i <= ace; i++ ){
					int curr = sum + 10*i;
				if (curr <= 21 ){
					res = max (res, curr );
				} // end 
		 	} // end for
		} // end if
		cout << res << endl;	
	} // end loop
		
	return 0;
}