#include <iostream>
#include <string>
#include <queue>

using namespace std;

int main() {
	queue<int> q;
	string a;
	while (true) {
		getline(cin, a);
		if (a[0] == '0') {
			break;
		}
		int counter = 0;
		int b = 0;
		int sum = 0;
		for (int i = 0; i <= a.size(); i++) {
			if (a[i] >= '0' && a[i] <= '9') {
				b *= 10;
				b += a[i] - '0';
			} else {
				if (b > 10) {
					b = 10;
				} else if (b == 1) {
					counter++;
				}
				sum += b;
				b = 0;
			}
		}
		while (counter > 0) {
			if (sum + 10 <= 21) {
				sum += 10;
				counter--;
			} else {
				break;
			}
		}
		if (sum > 21) {
			sum = 0;
		}
		q.push(sum);
	}
	while (!q.empty()) {
		cout << q.front() << endl;
		q.pop();
	}
	return 0;
}