#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  string s;
  while(getline(cin,s),s.size()!=1||s[0]!='0'){
    vector<int>num;
    rep(i,s.size()){
      int tmp=0;
      while(s[i]!=' '){
	tmp*=10;
	tmp+=s[i]-'0';
	i++;
	if(i==s.size())break;
      }
      if(tmp)num.pb(tmp);
    }
    //cout<<num[0]<<endl;
    int sum=0;
    int one=0;
    rep(i,num.size()){
      if(num[i]>10)num[i]=10;
      if(num[i]==1)one++;
      sum+=num[i];
    }
    rep(i,one){
      if(sum+10<=21)sum+=10;
    }
    if(sum>21)sum=0;
    cout<<sum<<endl;
  }


}