#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	for(;;){
		int sum = 0;
		int ace = 0;
		bool finish = false;
		do{
			int a;
			scanf("%d", &a);
			if(a == 0){
				finish = true;
				break;
			}
			if(a == 1)
				++ace;
			else
				sum += min(a, 10);
			
		}while(getchar() == ' ');
		
		if(finish)
			break;
		
		int best = 0;
		rep(i, ace+1){
			int now = sum + i + (ace-i) * 11;
			if(now > 21)
				now = 0;
			best = max(best, now);
		}
		
		printf("%d\n", best);
	}
	
	return 0;
}