
#include<iostream>
#include<string>
#include<cstring>
#include<cstdlib>
using namespace std;

int main()
{
  string s;
  char *c;
  int i, score, ace;
  while (getline(cin,s)) {
    if (s[0]=='0') break;
    score = 0;
    ace = 0;
    c = strtok((char*)s.c_str(), " ");
    while (c != NULL) {
      if (atoi(c) > 9) score += 10;
      else score += atoi(c);
      if (atoi(c) == 1) ace++;
      c = strtok(NULL, " ");
    }
    while (ace--) {
      if (score + 10 > 21) break;
      score += 10;
    }
    if (score > 21) score = 0;
    cout<<score<<endl;
  }
}