#include <bits/stdc++.h>
using namespace std;

int main(){
  
  while(1){
    int n=0,card[100]={};
    string str;
    getline(cin,str);
    str+=' ';
    for(int i=0,num=0;i<str.size();i++){
      if(isdigit(str[i]))num=num*10+str[i]-'0';
      else card[n++]=num,num=0;
    }
    if(card[0]==0)break;
    sort(card,card+n,greater<int>());
    int score=0;
    for(int i=0;i<n;i++){
      if(card[i]>=10)score+=10;
      else if(card[i]>1)score+=card[i];
      else if(score+11+(n-i-1)<=21)score+=11;
      else score++;

    }
    cout <<(score<=21? score:0)<<endl;
  }
  return 0;
}