#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;

int one = 0;
vector<int> split(const string &str, char delim){
    istringstream iss(str); string tmp; vector<int> res;
    while(getline(iss, tmp, delim)){
        int n = atoi(tmp.c_str());
        if(n == 1) one++;
        else{
            if(n >= 10) n = 10;
            res.push_back(n);
        }
    }
    return res;
}

int main(){
    string str;
    while(getline(cin, str)){
        one = 0;
        int ans = 0;
        if(str == "0") break;
        vector<int> num = split(str, ' ');
        REP(i, num.size()) ans += num[i];


        int onenum = one * 11;
        REP(i, one){
            if(onenum + ans >= 22) onenum -= 10;
        }

        ans += onenum;
        ans = (ans < 22)? ans : 0;
        cout <<ans <<endl;
    }
    return 0;
}