#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
string s;
vector<int> parse(string str) {
	vector<int> ret; str += " "; int t = 0;
	for(int i = 0; i < str.size(); i++) {
		if(str[i] == ' ') ret.push_back(t), t = 0;
		else t = t * 10 + str[i] - 48;
	}
	return ret;
}
int main() {
	while(s = "", getline(cin, s)) {
		if(s == "0") break;
		vector<int> v = parse(s);
		int a = 0, b = 0;
		for(int i = 0; i < v.size(); i++) {
			if(v[i] > 10) a += 10;
			else a += v[i];
			if(v[i] == 1) b++;
		}
		cout << ((a < 22) ? a + min(b, (21 - a) / 10) * 10 : 0) << endl;
	}
}