#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n;
string st;

int main(){
	while(getline(cin,st)){
		if(st=="0")return 0;
		int cur=0,p=0,one=0,s=0;
		while(cur<st.size()){
			if(isdigit(st[cur]))p=p*10+st[cur]-'0';
			if(st[cur]==' '){
				if(p==1)one++;
				if(p>10)s+=10;
				else s+=p;
				p=0;
			}
			cur++;
		}
		if(p==1)one++;
		if(p>10)s+=10;
		else s+=p;
		if(s>21)cout<<0<<endl;
		else{
			if(s<12&&one)cout<<s+10<<endl;
			else cout<<s<<endl;
		}
	}
}