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

int main(){
  while(1){
    int n=0,card[100];
    while(cin>>card[n++]);
    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(11+(n-i)<=21)score+=11;
      else score++;
    }
    cout <<(score<=21? score:0)<<endl;
  }
  return 0;
}