#include <iostream>
#include <vector>
#include <sstream>

using namespace std;
int saiki(int ten,int ind,vector<int> &v){
    if(ind == v.size()){
        if(ten >= 22) return 0;
        return ten;
    }
    int t = v[ind];
    if(v[ind] >= 10) t=10;
    if(v[ind] == 1){
        return max(saiki(ten+11,ind+1,v),saiki(ten+1,ind+1,v));
    }else{
        return saiki(ten+t,ind+1,v);
    }
}

int main(){
    string s;
    while(getline(cin,s)){
        stringstream ss(s);
        vector<int> v;
        int n;
        while(ss>>n){
            if(n==0) goto out;
            v.push_back(n);
        }
        cout << saiki(0,0,v) << endl;
    }
 out:
    return 0;
}