#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>

using namespace std;

typedef long long ll;

#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

int main()
{
    string s, t;
    int sum, ones;
    while(getline(cin, s) && s != "0") {
        s += " ";
        t = "";
        sum = ones = 0;
        for(int i = 0; i < s.size(); i++) {
            if(s[i] == ' ') {
                if(atoi(t.c_str()) == 1) {
                    ones++;
                } else {
                    if(atoi(t.c_str()) < 10) {
                        sum += atoi(t.c_str());
                    } else {
                        sum += 10;
                    }
                }
                t.clear();
            } else {
                t += s[i];
            }
        }
        sum += ones * 11;
        for(; ones-- && sum > 21;)
            sum -= 10;

        printf("%d\n", (sum > 21 ? 0 : sum));
    }
}