#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

        istringstream iss(s);
        int ret = 0;
        int num1 = 0;
        for(;;){
            int a;
            if(!(iss >> a))
                break;
            if(a > 10)
                a = 10;
            if(a == 1){
                ++ num1;
                a = 11;
            }
            ret += a;
            while(ret > 21 && num1 > 0){
                ret -= 10;
                -- num1;
            }
        }

        if(ret > 21)
            ret = 0;
        cout << ret << endl;
    }
}