#include <iostream>
#include <vector>
#include <sstream>

using namespace std;

int ten(vector<int> &cards,int index,int score){
    if(index == cards.size()){
        if(score >= 22) return 0;
        return score;
    }
    if(cards[index] >= 10) return ten(cards,index+1,score+10);
    if(cards[index] >= 2) return ten(cards,index+1,score+cards[index]);
    if(cards[index] == 1){
        return max(ten(cards,index+1,score+11),ten(cards,index+1,score+1));
    }
}

int main(){
    string s;
    while(getline(cin,s)){
        if(s=="0") break;
        stringstream ss;
        ss << s;
        vector<int> c;
        int temp;
        while(ss >> temp) c.push_back(temp);
        cout << ten(c,0,0) << endl;
    }
}