#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
int main(){
	string s;
	int sum,ans,now,cou,pre;
	priority_queue<int> que;
	while(getline(cin,s),s[0]!='0'){
		sum=0;
		for(int i=0;i<s.size();i++){
			if(isdigit(s[i])){
					sum=sum*10+(s[i]-'0');
			}
			else{
				que.push(sum);
				sum=0;
			}
		}
		cou=0;
		que.push(sum);
		ans=0;
		while(!que.empty()){
			now=que.top();
			que.pop();
			if(now>=2&&now<=9)
				ans+=now;
			else if(now>9)
				ans+=10;
			else if(now==1)
				cou++;
		}
		int m=ans;
		for(int i=0;i<=cou;i++){
			pre=m+cou-i+i*11;
			if(pre<=21){
				ans=max(pre,ans);
			}
		}
		if(ans>21)
		cout<<'0'<<endl;
		else cout<<ans<<endl;
	}
	return 0;
}