#include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
    string s;
    while(1){
        getline(cin,s);
        if(s=="0")break;
        s+=" ";
        vector<string> st;
        string buf="";
        rep(i,s.size()){
            if(s[i]!=' ')buf+=s[i];
            else{
                st.pb(buf);
                buf="";
            }
        }
        
        int score=0;
        int c=0;
        rep(i,st.size()){
            if(st[i]!="1"){
                int num=stoi(st[i]);
                if(10<=num)score+=10;
                else score+=num;
            }
            else{
                score+=1;
                c++;
            }
        }
        rep(i,c){
            if(21-score>=10)score+=10;
        }
        if(score>21)cout<<"0"<<endl;
        else cout<<score<<endl;
    }
}