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

int calc(int card[], int num) {
  int sum = 0;
  int A = 0;
  int Ap[12][2] = {{0,0},{1,11},{2,12},{3,13},{4,14},{5,15},{6,16},{7,17},{8,18},{9,19},{10,20},{11,21}};
  for(int i = 0; i < num; i++) {
    if(card[i] != 1) {
      if(card[i] >= 10) {
	sum += 10;
      } else {
	sum += card[i];
      }
    } else {
      A++;
    }
  }
  int best = -1;
  if(A >= 12) {
    sum += A;
    A = 0;
  }
  for(int i = 0; i < 2; i++) {
    int temp = sum + Ap[A][i];
    if(temp > 21) temp = 0;
    if(temp > best) best = temp;
  }

  return best;
}

int main() {
  while(1) {
    string str;
    getline(cin, str);
    if(str == "0") break;

    stringstream sin;
    sin << str;
    int card[1000];
    fill(&card[0], &card[999]+1, 0);
    int num;
    for(int i = 0; i < 1000; i++) {
      if(!(sin >> card[i])) {
	num = i;
	break;
      }
      if(i+1 == 1000) {
	num = 1000;
	break;
      }
    }
    cout << calc(card, num) << endl;
  }
  return 0;
}