#include <iostream>
#include <sstream>
using namespace std;

int main()
{
	string str;
	while(getline(cin, str)){
		if(str[0] == '0')
			break;
		stringstream sst;
		sst << str;
		int a;
		int sum = 0;
		int onecount = 0;
		while(sst >> a){
			if(a == 1){
				sum += 1;
				onecount++;
			}
			else if(a > 10){
				sum += 10;
			}else{
				sum += a;
			}
		}
		if(sum > 21)
			sum = 0;
		while(true){
			if(sum+10 <= 21 && onecount!=0){
				sum += 10;
				onecount--;
			}
			else
				break;
		}
		cout << sum << endl;
	}
	return 0;
}