#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
vector<string> split(string inp);
int main(){
    string input;
    while(true){
        getline(cin, input);
        vector<string> data;
        data = split(input);
        if (atoi(input.c_str()) == 0) {
            break;
        }
        int score1 = 0;
        int score2 = 0;
        for(vector<string>::iterator it = data.begin(); it != data.end(); it++) {
            int point = atoi((*it).c_str());
            if (point >= 2 && point <= 9) {
                score1 += point;
                score2 += point;
            }
            else if (point >= 10) {
                score1 += 10;
                score2 += 10;
            }
            else if (point == 1) {
                score1 += 1;
                score2 += 11;
            }
        }
        if (score1 > 21) {
            if (score2 > 21) {
                cout << "0" << endl;
            }
            else {
                cout << score2 << endl;
            }
        }
        else if (score2 > 21) {
            cout << score1 << endl;
        }
        else {
            if (score2 >= score1) {
                cout << score2 << endl;
            }
            else {
                cout << score1 << endl;
            }
        }
    }
}
vector<string> split(string inp){
    int length = inp.length();

    string::iterator it = inp.begin();

    vector<string> ret;

    vector<char> tmp;

    while (true) {
        if (it == inp.end()) {
            //in
            char t[tmp.size()+1];
            int i = 0;
            for(vector<char>::iterator cit = tmp.begin(); cit != tmp.end(); cit++){
                t[i] = *cit;
                i++;
            }
            t[i] = '\0';
            string push = t;
            ret.push_back(push);
            tmp.clear();
            break;
        }
        if (*it == ' ') {
            //in
            char t[tmp.size()+1];
            int i = 0;
            for(vector<char>::iterator cit = tmp.begin(); cit != tmp.end(); cit++) {
                t[i] = *cit;
                i++;
            }
            t[i] = '\0';
            string push = t;
            ret.push_back(push);
            tmp.clear();
        }
        else {
            tmp.push_back(*it);
        }
        it++;
    }
    return ret;
}