#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;

int main(){
  

  char n,m;
  int a,c = 0,sum = 0,sw = 0;

  while(1){  
    while(1){
      scanf("%c",&n);
      if(n == '0' && sw == 0) break;
      if(n != ' ' && sw != 1 && n != '\n'){
	sw = 1;
	a = atoi(&n);
	continue;
      }
      else if(n!=' ' && sw == 1 && n !='\n'){
	sw = 0;
	a = a * 10 + atoi(&n);
	continue;
      }
      else if(n == ' '){
	sw = 0;
      }
  
      cout << "a = " << a << endl;    

      if(a >= 2 && a <= 9) sum += a;
      if(a >= 10 && a <= 13 ) sum += 10;
      if(a == 1) {
	sum += a;
	c++;
      }
      if(n == '\n') break; 
    }
    if(n == '0' && sw == 0) break;

    for(int j = 0;j < c; j++){
      if(sum + 10 <= 21) sum += 10;
      else break;
    }

    if(sum <= 21) cout << sum << endl;
    else cout << '0' << endl;
    c=0;
    sum=0;
    sw = 0;
     
  }
 
}