#include <bits/stdc++.h>
using namespace std;

vector<int> v;

int dp(int p, int n){
    if(p == v.size() && n <= 21) return n;
    else if(21 < n) return 0;
    else {
        if(v[p] == 1){
            return max(dp(p+1, n+1), dp(p+1, n+11));
        }
        else return dp(p+1, n+v[p]);
    }
}

int main(){
    string input;
    while(getline(cin, input), input != "0"){
        int n;
        v.clear();
        while(input.find_first_of(" ") != string::npos){
            n = atoi(input.substr(0, input.find_first_of(" ")).c_str());
            if(n/10 == 1) n = n-n%10;
            v.push_back(n);
            input = input.substr(input.find_first_of(" ")+1);
        }
        n = atoi(input.c_str());
        v.push_back(n);

        cout << dp(0, 0) << endl;
    }
}