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

int ans;

vector<int> split(string s){
 	int n=0;
	vector<int> vc;
 	s += " ";
	for(int i=0 ; i < s.size() ; i++ ){
		if( s[i] == ' ' ){
			vc.push_back( n );
 			n = 0;
		}else if( s[i] >= '0' && s[i] <= '9' ){
			n = n*10 + (s[i] - '0');
		}
	}
	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) , s != "0" ){
		vector<int> a = split(s);
		ans = 0;
		solve( a , 0 , 0 );
		cout << ans << endl;
	}
}