#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

int main(){
	string S;
	while(getline(cin,S)){
		priority_queue<int,vector<int>,greater<int> > pq[2]; pq[0].push(0);
		int cnt = 0;
		for(int i=0;i<S.size();i++){
			if(i==0 || S[i]==' '){
				int n = stoi(&S[i]);
				if(n==0) return 0;
				while(!pq[cnt&1].empty()){
					int pq_c = pq[cnt&1].top(); pq[cnt&1].pop();
					if(pq_c>21) continue;
					if(n==1) pq[(cnt+1)&1].push(pq_c+1), pq[(cnt+1)&1].push(pq_c+11);
					else if(n<10) pq[(cnt+1)&1].push(pq_c+n);
					else pq[(cnt+1)&1].push(pq_c+10);
				}
				cnt++;
			}
		}
		int ans = 0;
		while(!pq[cnt&1].empty()){
			if(pq[cnt&1].top()<=21) ans = max(ans,pq[cnt&1].top());
			pq[cnt&1].pop();
		}
		printf("%d\n",ans);
	}
	return 0;
}