#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;
vi cards;
int ans;
void solve(int dep,int sum){
    if(dep == cards.size()){
        ans = max(ans,sum);
        return ;
    }
    if(cards[dep] == 1){
        if(sum+1 > 21){
            solve(dep+1,0);
        }
        else{
            solve(dep+1,sum+1);
        }

        if(sum+11 > 21){
            solve(dep+1,0);
        }
        else{
            solve(dep+1,sum+11);
        }
    }
    else if(cards[dep] > 9){
        if(sum+10 > 21){
            solve(dep+1,0);
        }
        else{
            solve(dep+1,sum+10);
        }
    }
    else{
        if(sum+cards[dep] > 21){
            solve(dep+1,0);
        }
        else{
            solve(dep+1,sum+cards[dep]);
        }
    }
    return ; 
}
int main(){
    string str;
    while(getline(cin,str)){
        stringstream ss(str);
        int tmp;
        cards.clear();
        while(ss >> tmp){
            cards.PB(tmp);
        }
        if(cards[0] == 0)break;
        ans = -INF;
        solve(0,0);
        printf("%d\n",ans);
    }
    return 0;
}