#include <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

int main(){
	char buf[400];
	int checkTable[14],tmp,sum;

	while(true){
		fgets(buf,400,stdin);
		if(buf[0] == '0')break;

		for(int i= 1; i <= 13; i++){
			checkTable[i] = 0;
		}

		sum = tmp = 0;
		for(int i=0; buf[i] != '\n' && buf[i] != '\0'; i++){
			if(buf[i] >= '0' && buf[i] <= '9'){
				tmp = 10*tmp + (buf[i] - '0');

				if(buf[i+1] == '\n' || buf[i] == '\0'){
					checkTable[tmp]++;
				}
			}else{
				checkTable[tmp]++;
				tmp = 0;
			}
		}

		for(int i=10; i <= 13; i++)sum += 10*checkTable[i];
		for(int i= 9; i >= 2; i--)sum += i*checkTable[i];

		if(sum > 21)printf("0\n");
		else{
			if(checkTable[1] == 0)printf("%d\n",sum);
			else{
				if(sum + checkTable[1] > 21){
					printf("0\n");
				}else if(sum >= 11){
					printf("%d\n",sum+checkTable[1]);
				}else{
					int zero,one;

					zero = sum + checkTable[1];
					one = sum + 11 + checkTable[1]-1;
					if(one > 21)one = 0;

					sum = max(zero,one);

					printf("%d\n",sum);
				}
			}
		}
	}

    return 0;
}