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

using namespace std;

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);
        bitset<22> bits;
        bits.set(0);
        for(int i=0;i<c.size();i++){
            bitset<22> newbits;
            int x = c[i];
            for(int j=0;j<22;j++){
                if(!bits[j]) continue;
                if(x>=10) x = 10;
                if(x != 1 && j+x <= 21) newbits.set(j+x);
                if(x == 1){
                    if(j+11 <= 21) newbits.set(j+11);
                    if(j+1 <= 21) newbits.set(j+1);
                }
            }
            bits = newbits;
        }
        int mm=0;
        for(int i=0;i<22;i++){
            if(bits[i]) mm = i;
        }
        cout << mm << endl;
    }
}