#include<bits/stdc++.h>
using namespace std;
int power(int n)
{
???int num=1;
???for(int i=0;i<n;i++)num*=10;
???return num;
}
int serch(int sum,int n)
{
???if(sum>21)return 0;
???else if(n==0)return sum;
???else return max(serch(sum+11,n-1),serch(sum+1,n-1));
}
int main()
{
???string str;
???while(getline(cin,str)){
??????if(str[0]=='0')break;
??????int card[1000]={},co=0,point=0;
??????for(int i=0;;i++){
?????????if(str[i]==' '||str[i]=='\0'){
????????????for(int j=point;j<i;j++)card[co]+=(str[j]-'0')*power(i-1-j);
????????????co++;point=i+1;
?????????}
?????????if(str[i]=='\0')break;
??????}
??????int cou=0,sum=0;
??????for(int i=0;i<co;i++){
?????????if(card[i]==1)cou++;
?????????else if(card[i]<10)sum+=card[i];
?????????else sum+=10;
??????}
??????cout<<serch(sum,cou)<<endl;
???}
}