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

int Parse(string a) {
	int s = 0;
	for (int b = 0; b < a.length(); b++) {
		s *= 10;
		s += a[b] - 48;
	}
	return s;
}
int main() {
	string a;
	while (1) {
		getline(cin, a);
		if (a == "0")break;
		vector<int>s;
		string c="";
		for (int b = 0; b < a.length(); b++) {
			if (a[b] == ' ') { s.push_back(Parse(c)); c = ""; }
			else c += a[b];
		}
		s.push_back(Parse(c));
		int m = 0;
		int n = 0;
		for (int d = 0; d < s.size(); d++) {
			if (s[d] > 9)m += 10;
			else if (s[d] > 1&&s[d]<10)m += s[d];
			else n++;
			if (m > 21) { cout << 0 << endl; goto l; }
		}
		if (m + 10 + n < 22)m += 10 + n;
		else m += n;
		if (m > 21)m = 0;
		cout << m << endl;
	l:;
	}
}