#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main() {
  while( 1 ) {
    string line;
    getline( cin, line );
    vector<int> cards;
    istringstream iss(line);
    string item;
    while( iss >> item ) {
      cards.push_back( atoi( item.c_str() ) );
    }
    if( !cards[ 0 ] ) { return EXIT_SUCCESS; }
    sort( cards.begin(), cards.end() );
    int one_num = 0;
    for( ; cards[ one_num ] == 1; one_num++ ); // counts '1' cards
      
    int len = cards.size();
    int sum = 0;
    for( int i = 0; i < len; i++ ) {
      sum += min( cards[ i ], 10 );
    }
    sum = ( sum > 21 ? 0 : sum ); 
    while( sum != 0 && one_num > 0 ) {
      if( sum + 10 > 21 ) break;
      sum += 10;
      one_num--;
    }
    cout << sum << endl;
  }
}