#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <functional>
using namespace std;

int calc_point(int* cards, int size) {
    int point = 0;
    sort(cards, cards+size, greater<int>());
    for (int i = 0; i < size; i++) {
        if (10 <= *(cards+i) && *(cards+i) <= 13) {
            point += 10;
        } else if (cards[i] != 1) {
            point += cards[i];
        } else {
            int remain_ace = size - i;
            while (remain_ace) {
                if (remain_ace == 1) {
                    if (point <= 10) {
                        point += 11;
                    } else {
                        point += 1;
                    }
                } else {
                    point += 1;
                }
                i++;
                remain_ace--;
            }
        }
    }
    if (point > 21) point = 0;
    return point;
}

#define MAX 1000
int main() {
    string s;
    int hand[MAX]; 
    while (getline(cin, s)) {
        if (s == "0") break;
        int i = 0;
        memset(hand, 0, sizeof(hand));
        istringstream ss; ss.str(s);
        while (ss >> hand[i++]);
        cout << calc_point(&hand[0], i-1) << endl;
    }
    return 0;
}

        