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

int main(){
    string str;
    
    while(getline(cin,str),str!="0"){
        int sum = 0,num,cnt=0;
        stringstream s;
        s << str;
        
        while(s >> num){
            if(2 <= num && num <= 9) sum += num;
            else if(num >= 10) sum += 10;
            else{
                sum++;
                cnt++;
            }
        }
        if(sum <= 11 && cnt){
            sum += 10;
            cnt--;
        }
        if(sum > 21) cout << '0' << endl;
        else cout << sum << endl;
    }
    
    return 0;
}