#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	string base;
	int sum,tmp,count;
	
	
	while(getline(cin,base)){
		if(base[0]=='0')break;
		base+=' ';
		count=sum=tmp=0;
		for(int i=0;i<base.size();i++){
			if(base[i]==' '){
				if(tmp>10)tmp=10;
				if(tmp==1)count++,tmp+=10;
				sum+=tmp;
				tmp=0;
			}
			else{
				tmp*=10;
				tmp+=(base[i]-'0');
			}
		}
		
		while(sum>21 && count>0){
			sum-=10;
			count--;
		}
		if(sum>21)cout<<0<<endl;
		else cout<<sum<<endl;
	}
	
	return 0;
}
