#include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
int A[5],B[5];
string rule[5][5];
#define pb push_back
string s;
int main(void)
{
  while(getline(cin,s) && s!="0")
    {
      int lowerten=0;
      int one=0;
      int score=0;
      int lastscore=0;
      string num="";
      //cout << int(s.size()) << endl;
      for(int i=0;i<int(s.size());i++)
	{
	  if(s[i]!=' ')
	    {
	      num+=s[i];
	    }
	  if(s[i]==' ' || i==int(s.size()-1))
	    {
	      int getnum=stoi(num);
	      if(getnum>=10) score+=10;
	      else if(getnum==1) one++;
	      else score+=getnum;
	      num="";
	    }
	}
      for(int i=0;i<=one;i++)
	{
	  int addscore=11*i+1*(one-i);
	  if(score+addscore>21)
	    {
	      continue;
	    }
	  else
	    {
	      lastscore=max(lastscore,score+addscore);
	    }
	}
      if(score>21)
	{
	  cout << 0 << endl;
	}
      else
	{
	  cout << lastscore << endl;
	}
    }
  return 0;
}

