#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    string s;
    while(getline(cin,s)){
        if(s=="0")break;
        
        vi in;
        string tmp="";
        rep(i,s.size()){
            if(s[i]!=' ')tmp+=s[i];
            else{
                int res=stoi(tmp);
                if(res>=10)res=10;
                in.pb(res);
                tmp="";
            }
        }
        in.pb(stoi(tmp));
        
        sort(all(in));
        reverse(all(in));
        
        int len=in.size();
        int sum=0;
        int one=0;
        rep(i,len){
            if(in[i]==1)one++;
            sum+=in[i];
        }
        while(sum<=11 && one>0){
            one--;
            sum+=10;
        }
        if(sum>21)sum=0;
        cout<<sum<<endl;
    
    }
    return 0;
}