#include<iostream>
#include<vector>
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(){
	while(true){
		int t;
		int one_num = 0;
		int ans = 0;
		vector< int > cards;
		
		scanf("%d", &t);
		if(t==0)
			break;
		cards.push_back( t );
		while( true ){
			char c;
			scanf("%c", &c);
			if( c == '\n' )
				break;
			else{
				scanf("%d", &t);
				cards.push_back( t );
			}
		}
		sort( cards.begin(), cards.end(), greater<int>() );
		for(unsigned int i = 0; i < cards.size(); ++i){
			one_num += cards[i] == 1 ? 1 : 0;
		}
		for(unsigned int i = 0; i < cards.size(); ++i){
			cards[i] = cards[i] > 10 ? 10 : cards[i];
			if( cards[i] == 1 ){
				int tt = one_num * 11;
				while( ans + tt > 21 ){
					tt -= 10;
				}
				if( tt < one_num )
					ans = 22;
				else
					ans = ans + tt;
				break;
			}else{
				ans += cards[i];
			}
		}
		printf("%d\n", ans > 21 ? 0 : ans);
	}
	return 0;
}