#include<iostream>
#include<sstream>
#include<string>
using namespace std;
int main(){
long a,b,c;
stringstream ss;
string s;
for(;;){
getline(cin,s);
if(s=="0")break;
ss.str("");ss.clear();
ss<<s;
b=c=0;
while(ss>>a){
if(a==1){c++;b+=11;}
else if(a>9)b+=10;
else b+=a;
}
while(b>21&&c>0){
b-=10;c--;
}
if(b>21)b=0;
cout<<b<<endl;
}
return 0;
}