#include<cstdio>
#include<vector>

using namespace std;

int main()
{
	for(int a;scanf("%d",&a),a;){
		vector<int> card;
		card.push_back(a);
		while(getchar()!='\n'){
			int b;
			scanf("%d",&b);
			card.push_back(b);
		}

		int cnt1=0,total=0;
		for(int i=0;i<card.size();i++){
			if(card[i]==1)	cnt1++;
			total+=card[i]>10?10:card[i];
		}

		for(int i=0;i<cnt1;i++,total+=10)
			if(total+10>21)	break;

		printf("%d\n",total>21?0:total);
	}

	return 0;
}