#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


vector<string> split(const string &s, char c = ' ') {
	vector<string> ret;
	stringstream ss(s);
	string t;
	while (getline(ss, t, c)) {
		ret.push_back(t);
	}
	return ret;
}



int main() {
	string s;
	vector<string> v;
	int p, t, n;
	while (getline(cin, s)) {
		v = split(s);
		if (v[0] == "0")break;
		p = 0;
		n = 0;
		for (int i = 0; i < v.size(); i++) {
			t = atoi(v[i].c_str());
			//cout << " " << t;
			if (t < 10)p += t;
			else p += 10;
			if (t == 1)n++;
		}
		//cout << endl;
		while (n > 0) {
			if (p + 10 <= 21)p += 10;
			n--;
		}
		if (p > 21)p = 0;
		cout << p << endl;
	}
}