#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
	string hands;
	while( getline( cin, hands ) ){
		if( hands == "0" ) break;
		stringstream ss( hands );
		int ans = 0;
		int ex = 0;
		while( !ss.eof() ){
			int p;
			ss >> p;
			if( p > 10 ){
				p = 10;
			}
			if( p == 1 ){
				++ex;
			}
			ans += p;
		}
		while( ex > 0 ){
			if( 21 - ans >= 10 ){
				ans += 10;
			}
			--ex;
		}
		cout << ( ans > 21 ? 0 : ans ) << endl;
	}
}