#include<iostream>
#include<string>
using namespace std;
int main(){
	string a;
	while (getline(cin, a) && a!="0") {
		a += " ";
		int c = 0, sum = 0;
		string h = "";
		for (int i = 0; i < a.length(); i++) {
			if (a[i] == ' ') {
				int d = atoi(h.c_str());
				h = "";
				if (d == 1) c++;
				else {
					if (d == 10 || d == 11 || d == 12 || d == 13)
						sum += 10;
					else sum += d;
				}
			}
			else h += a[i];
		}
		if (sum > 21) {
			cout << 0 << endl;
			goto stop;
		}
		else {
			sum += c;
			if (sum > 21) {
				cout << 0 << endl;
				goto stop;
			}
			else {
				while ((21 - sum) >= 10&&c!=0) {
					sum += 10;
					c--;
				}
			}
		}
		cout << sum << endl;
	stop:;
	}
}