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

int ans;

vector<int> split(string s){
	int n=0;
	vector<int> vc;

	for(int i=0 ; i < s.size() ; i++ ){
		char c = s[i];
		if( c == ' ' ){
			vc.push_back( n );
			n = 0;
		}else if( c >= '0' && c <= '9' ){
			n *= 10;
			n += c - '0';
			if( i == s.size()-1 )
				vc.push_back( n );
		}
	}
	return vc;
}

void solve(const vector<int>& a,int i,int p){
	if( p > 21 ){
		return;
	}
	if( i == a.size() ){
		ans = max( ans , p );
		return;
	}

	if( a[i] == 1 ){
		solve( a , i+1 , p+1  );
		solve( a , i+1 , p+11 );
	}else if( a[i] >= 10 ){
		solve( a , i+1 , p+10 );
	}else{
		solve( a , i+1 , p+a[i] );
	}
}

int main(){
	string s;
	while( getline(cin,s) ){
		vector<int> a = split(s);
		if( a.size() == 1 && a[0] == 0 ) break;

		ans = 0;
		solve( a , 0 , 0 );
		cout << ans << endl;
	}
}