#include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
    string str;
    while(getline(cin,str)){
        stringstream ss(str);
        int tmp;
        vi cards;
        while(ss >> tmp){
            cards.PB(tmp);
        }
        sort(cards.begin(),cards.end());
        if(cards[0] == 0)break;
        stack < int > S[2];
        S[0].push(0);
        rep(i,cards.size()){
            while(S[i%2].size()){
                int x = S[i%2].top();
                S[i%2].pop();
              //  cout << x << "\n";
                if(x > 21)x=0;
                if(cards[i] == 1){
                    S[1-i%2].push(x+1);
                    S[1-i%2].push(x+11);
                }
                else if(cards[i] > 9){
                    S[1-i%2].push(x+10);
                }
                else{
                    S[1-i%2].push(x+cards[i]);
                }
            }
        }
        int ans = 0;
        while(S[cards.size()%2].size()){
            int ret = S[cards.size()%2].top();
            S[cards.size()%2].pop();
            if(ret > 21){
                continue;
            }
            ans = max(ans,ret);
        }
        printf("%d\n",ans);
    }
    return 0;
}