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

int calc(int card[5], int score=0, int cnt=0) {
  static int max;
  if(cnt == 0) max = -1;

  if(cnt == 5) {
    if(score > 21) score = 0;
    if(score > max) max = score;
    return 0;
  }

  if(card[cnt] == 1) {
    calc(card, score+1, cnt+1);
    calc(card, score+11, cnt+1);
  } else if(card[cnt] > 10) {
    calc(card, score+10, cnt+1);
  } else {
    calc(card, score+card[cnt], cnt+1);
  }

  if(cnt == 0) return max;
}

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

    stringstream sin;
    sin << str;
    int card[5];
    fill(&card[0], &card[4]+1, 0);
    int num;
    for(int i = 0; i < 5; i++) {
      if(!(sin >> card[i])) {
	num = i;
	break;
      }
      if(i+1 == 5) {
	num = 5;
	break;
      }
    }

    cout << calc(card) << endl;
  }
  return 0;
}