#define _USE_MATH_DEFINES
#define MAX_N 1000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 1e-8;

vector<int> split(string delim,string str){
	vector<int> res;
	str += delim;
	for(int i=0;i<str.size();i++){
		for(int j=1;i+j<=str.size();j++){
			if(str.substr(i,j).find(delim) != string::npos){
				int num = atoi(str.substr(i,j-1).c_str());
				if(str.substr(i,j-1).size() >0 ) res.push_back(num);
				i+=j-1;
				break;
			}
		}
	}

	return res;
}

void dfs(const vector<int>& data, int i,int sum,int* res){

	if(i==data.size()){
		if(sum <=21 && abs(*res-21) > abs(sum-21)){
			*res=sum;
		}
		return;
	}
	if(data[i] == 1){
		dfs(data,i+1,sum+1,res);
		dfs(data,i+1,sum+11,res);
	}
	else if(2 <= data[i] && data[i] <= 9){
		dfs(data,i+1,sum+data[i],res);
	}
	else{
		dfs(data,i+1,sum+10,res);
	}
}

int main(){
	string str;
	while(getline(cin,str)){
		vector<int> data = split(" ",str);
		if(data.size()==1 && data[0]==0) break;
		int res=10000;
		dfs(data,0,0,&res);
		printf("%d\n",res == 10000 ? 0 : res);
	}
}