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

int main()
{
  int n;
  char c;

  while (1){
    int sum = 0, ace = 0;
    bool fin = false;
    do {
      scanf("%d", &n);
      if (n == 0){
        fin = true;
        break;
      }
      if (n == 1){
        ace++;
      }
      else {
        sum += min(n, 10);
      }
    } while (scanf("%c", &c), c != '\n');

    if (fin){
      break;
    }
    int rs = 0;
    for (int i = 0; i <= ace; i++){
      int tmp = sum + i + (ace - i) * 11;
      if (tmp > 21){
        tmp = 0;
      }
      rs = max(tmp, rs);
    }
    printf("%d\n", rs);
  }

  return (0);
}