#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<utility>
#include<cmath>
#include<sstream>
using namespace std;
#define all(a) a.begin(),a.end()


int main()
{
	string s;
	while(getline(cin,s))
	{
		if(s=="0")break;
		stringstream ss(s);
		int sum=0,c=0;
		int x;
		while(ss>>x)
		{
			sum+=min(10,x);
			if(x==1)c++;
		}
		while(sum+10<=21&&c)
		{
			c--;
			sum+=10;
		}
		if(sum>21)sum=0;
		
		cout<<sum<<endl;
	}
}