#include<cstdio>
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
#include<stack>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int main(void){
  string str;
  while(getline(cin,str),str!="0"){
    int a,b,c;  a = b = c = 0;
    bool one = false;
    int sum = 0;
    for(int i = 0 ; i < str.size() ; i ++){
      if(str[i]==' ')continue;
      //--
      if(str[i] == '1') {
	if(str[i+1] == ' '){
	  one = true;
	  sum ++;
	}else if(str[i+1]=='\0'){
	  one = true;
	  sum ++;
	}else {
	  sum += 10;
	  i++;
	}
      }
      //--

      else{
	sum += str[i] - '0';
      }

    }
    if(one && sum + 10 <= 21) sum += 10;
    //cout<<sum<<endl;
    cout<<(sum<=21?sum:0)<<endl;
  }
}