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

int main() {
  string str;
  vector<int> card;
  while(getline(cin,str)) {
    if(str == "0") break;
    int score=0,ace=0;
    stringstream ss;
    int s;
    ss << str;
    while(ss >> s) {
      card.push_back(s);
    }
    ss.str("");
    ss.clear(stringstream::goodbit);



    for(unsigned int i=0;i<card.size();i++) {
      if(2 <= card[i] && card[i] <= 9) {
        score += card[i];
      }
      else if(10 <= card[i] && card[i] <= 13) {
        score += 10;
      }
      else { //card[i]==1
        ace++;
      }
    }

    if(score > 21) {
      cout << 0 << endl;
      card.clear();
      continue;
    }

    while(ace>0) {
      if(score + ace <= score + 11 + ace - 1 && score + 11 + ace - 1 <= 21) {
        score += 11;
      }
      else {
        score += 1;
      }
      ace--;
    }

    if(score > 21) {
      cout << 0 << endl;
    }
    else cout << score << endl;
    card.clear();
  }
}