#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    while(getline(cin, s), s != "0"){
        vector<int> v{0};
        for (auto &&i : s) {
            if(i == ' ') v.emplace_back();
            else v.back() = v.back()*10 + i-'0';
        }
        int val = 0, one = 0;
        for (auto &&i : v) {
            val += min(i, 10);
            one += (i == 1);
        }
        while(val <= 11 && one){
            val += 10;
            one--;
        }
        if(val > 21) val = 0;
        cout << val << "\n";
    }
    return 0;
}
