#include <iostream>
#include <string>
using namespace std;

int main() {
    string line;
    while (getline(cin, line)){
        if (line.size() == 1 && line[0] == '0') {
            break;
        }
        int cards[11] = {};
        while (line.empty() == false) {
            size_t erase = 2;
            if (line.size() == 1 || line[1] == ' ') {
                cards[line[0] - '0']++;
            } else {
                cards[10]++;
                erase = 3;
            }
            line.erase(0, erase);
        }
        int result = 0;
        for (int i = 1; i < 11; i++) {
            result += i * cards[i];
        }
        while (cards[1] > 0) {
            if (result < 12) {
                result += 10;
                cards[1]--;
            } else {
                break;
            }
        }
        if (result > 21) {
            result = 0;
        }
        cout << result << endl;
    }
}