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

int card[50];

int main(void){
	while(1){
		string str;
		getline(cin,str);
		stringstream ss(str);
		vector<string> v;
		string buffer;
		int sum=0,cnt=0;
		while(getline(ss,buffer,' '))v.push_back(buffer);
		if(v[0]=="0")break;
		for(int i=0;i<v.size();i++){
			stringstream iss(v[i]);
			iss >> card[i];
			if(card[i]==1)cnt++;
			if(card[i]>=2 && card[i]<=9)sum+=card[i];
			if(card[i]>=10)sum+=10;
		}
		if(sum>21)printf("0\n");
		else{
			int maxp=0;
			for(int i=0;i<=cnt;i++){
				int p=sum+1*i+11*(cnt-i);
				if(p>21)continue;
				maxp=max(maxp,p);
			}
			printf("%d\n",maxp);
		}
	}
	return 0;
}