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

int main() {
	while(1) {
		string s;
		getline(cin, s);
		stringstream sstr(s);

		int n;
		int one_count = 0, pts = 0;
		sstr >> n;
		if(n == 0)
			break;
		do {
			if(n == 1)
				one_count++;
			else if(n < 10)
				pts += n;
			else
				pts += 10;
		} while(sstr >> n);

		int ret = pts + one_count;
		ret = ret <= 21 ? ret : 0;
		for(int i = 0; i <= one_count; i++) {
			int tmp;
			tmp = pts + i + 11 * (one_count - i);
			tmp = tmp <= 21 ? tmp : 0;

			ret = ret > tmp ? ret : tmp;
		}

		cout << ret << endl;
	}
}