#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
//#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;


signed main() {
	vi d;
	while(1){
		int a;
		char c;
		scanf("%d%c",&a,&c);
		if(a == 0) break;
		d.push_back(a);
		if(c == '\n'){
			int sum = 0;
			int f = 0;
			rep(i, 0, d.size()){
				//cout <<d[i]<<" ";
				if(d[i] == 1) f ++;
				else sum += min(10, d[i]);
			}
			if(f){
				if(21 - sum - f + 1 >= 11) sum += 11 + f - 1;
				else sum += f;
			}
			cout<< (sum > 21 ? 0 : sum) << endl;
			d.clear();
		}
	}
}