//53
#include<iostream>
#include<string>
#include<sstream>

using namespace std;

int main(){
  for(string s;getline(cin,s),s!="0";){
    stringstream ss(s);
    int p=0,o=0;
    for(int c;ss>>c;){
      if(c==1){
	o++;
      }else if(c>=10){
	p+=10;
      }else{
	p+=c;
      }
    }
    while(o&&p+11+o-1<=21){
      p+=11;
      o--;
    }
    p+=o;
    cout<<((p>21)?0:p)<<endl;
  }
  return 0;
}