#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

void solve()
{
	string str;
	while(getline(cin, str))
	{
		if(str[0] == '0')
		{
			return;
		}
		vector<int> Vec;
		string temp;
		int size = str.size();
		for(int i = 0; i < size; ++i)
		{
			if(str[i] == ' ')
			{
				int a;
				int multi = 1;
				int size2 = temp.size();
				for(int i = size2 - 1; i >= 0; --i)
				{
					a = (temp[i] - '0') * multi;
					multi *= 10;
				}
				Vec.push_back(a);
				temp.clear();
			}
			else
			{
				temp += str[i];
			}
		}
		int a;
		int multi = 1;
		int size2 = temp.size();
		for(int i = size2 - 1; i >= 0; --i)
		{
			a = (temp[i] - '0') * multi;
			multi *= 10;
		}
		Vec.push_back(a);
		temp.clear();
		
		int max;
		queue<int> Que;
		queue<int> NextQue;
		if(Vec[0] == 1)
		{
			Que.push(1);
			Que.push(11);
		}
		else if(10 <= Vec[0] && Vec[0] < 14)
		{
			Que.push(10);
		}
		else
		{
			Que.push(Vec[0]);
		}
		size = Vec.size();
		int pos = 1;
		while(pos != size)
		{
			while(!Que.empty())
			{
				int Front;
				if(Vec[pos] == 1)
				{
					Front = Que.front() + 1;
					NextQue.push(Front);
					Front = Que.front() + 11;
					NextQue.push(Front);
				}
				else if(10 <= Vec[pos] && Vec[pos] < 14)
				{
					Front = Que.front() + 10;
					NextQue.push(Front);
				}
				else
				{
					Front = Que.front() + Vec[pos];
					NextQue.push(Front);
				}
				Que.pop();
			}
			while(!NextQue.empty())
			{
				Que.push(NextQue.front());
				NextQue.pop();
			}
			pos++;
		}
		if(Que.size() == 1)
		{
			if(Que.front() > 21)
			{
				max = 0;
			}
			else
			{
				max = Que.front();
			}
		}
		else
		{
			vector<int> result;
			while(!Que.empty())
			{
				result.push_back(Que.front());
				Que.pop();
			}
			sort(result.begin(), result.end());
			max = result[0];
			size = result.size();
			for(int i = 0; i < size; ++i)
			{
				if(result[i] <= 21)
				{
					max = result[i];
				}
			}
		}
		cout << max << endl;
	}
}

int main()
{
	solve();
	return(0);
}