#include <iostream>
#include <vector>
#include <sstream>
using namespace std;

int main(){
    string str;
    while(getline(cin, str)){
        stringstream ss;
        vector<int> hand;
        if(str == "0") break;
        int begin = 0;
        int point = 0;
        int one = 0;
        bool isbust = false;
        for(int i=0; i<str.size(); i++){
            if(str[i] == ' ' || i == str.size()-1){
                int tmp;
                ss << str.substr(begin, i-begin+1);
                ss >> tmp;
                if(tmp < 10){
                    hand.push_back(tmp);
                }else{
                    hand.push_back(10);
                }
                begin = i + 1;
            }
        }
        for(int i=0; i<hand.size(); i++){
            if(hand[i] == 1){
                one++;
            }else{
                point += hand[i];
            }
        }
        point += one*11;
        while(one--&&point>21){
            point -= 10;
        }
        if(point > 21){
            cout << "0" << endl;
        }else{
            cout << point << endl;
        }
    }
    return 0;
}