#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <iterator>
using namespace std;

vector<int> parse(string s) {
    istringstream iss(s);
    vector<int> res;
    for(int n; iss >> n; ) {
        if(n > 10) n = 10;
        res.push_back(n);
    }
    return res;
}

int main() {
    for(string line; getline(cin, line), line != "0"; ) {
        vector<int> cards = parse(line);
        int one = 0;
        for(int c : cards) if(c == 1) one++;
        int s = accumulate(begin(cards), end(cards), 0);
        for(int i = 0; i < one; i++) {
            if(s + 10 <= 21) s += 10;
        }
        if(s > 21) s = 0;
        cout << s << endl;
    }
}