#include <iostream>
#include <sstream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
	while(1) {
		char input[1024];
		cin.getline(input, sizeof input);
		if(strcmp(input, "0") == 0) {
			break;
		}
		stringstream ss(input);
		vector<int> v;
		int num;
		while(ss >> num) {
			v.push_back(num);
		}
		sort(v.begin(), v.end(), greater<int>());
		int n = v.size();
		int sum = 0;
		for(int i = 0; i < n; i++) {
			if(v[i] == 1) {
				if(sum + 10 >= 21 - (n - i + 1)) {
					sum++;
				} else {
					sum += 10;
				}
				continue;
			}
			else if(v[i] >= 10) {
				sum += 10; continue;
			} else {
				sum += v[i];
			}
		}
		if(sum > 21) cout << 0 << endl;
		else cout << sum << endl;
	}
	return 0;
}