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

int pos = 0;

int read(string s){
	int tmp = 0;
	while(s[pos] == ' ') pos++;
	while(s[pos] != ' '){
		tmp = tmp * 10 + s[pos++] - '0';
	}
	return tmp;
}

int main(){
	string s;
	while(getline(cin,s)){
		pos = 0;
		int one = 0,sum = 0;
		if(s == "0") break;
		s += " ";
		for(int i = 0;pos < s.length() - 1;i++){
			int num = read(s);
			if(num == 1) one++;
			if(num >= 10) num = 10;
			sum += num;
		}
		while(sum <= 11 && one){
			one--;
			sum += 10;
		}
		if(sum > 21) cout << 0 << endl;
		else cout << sum << endl;
	}
}