#include "bits/stdc++.h"
using namespace std;
int main(){
    string s;
    while(getline(cin,s)){
        if(s=="0") break;
        stringstream ss;
        vector<int> a;
        int n,f=0,sum=0;
        ss<<s;
        while(ss>>n){
            if(n==1)f=1;
            a.push_back((n>=10)?10:n);
            if(ss.eof()) break;
        }
        for(int i=0;i<a.size();++i) sum+=a[i];
        if(f&&sum<=11) sum+=10;
        if(sum>21)cout<<0<<endl;
        else cout<<sum<<endl;
    }
    return 0;
}