#include <bits/stdc++.h>
using namespace std;

int main(){
    while(1){
        string s;
        getline(cin, s);
        if(s == "0") return 0;

        int n = s.size();
        int sum = 0;
        int cnt1 = 0;
        for(int i=0; i<n; i++){
            string t = "";
            while(i < n && '0' <= s[i] && s[i] <= '9'){
                t += s[i];
                i++;
            }
            int num = stoi(t);
            if(10 <= num) sum += 10;
            else if(1 < num) sum += num;
            else{
                cnt1++;
                sum++;
            }
        }

        vector<int> v;
        v.emplace_back(sum);

        for(int i=1; i<=cnt1; i++){
            sum += 10;
            v.emplace_back(sum);
        }

        sort(v.begin(), v.end(), greater<int>());

        bool valid = false;
        for(auto i : v){
            if(21 >= i){
                cout << i << endl;
                valid = true;
                break;
            }
        }

        if(!valid){
            cout << 0 << endl;
        }
    }
}
