#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define f first
#define s second

main(){
  string str;
  while(getline(cin,str)){
    if(str[0]=='0')break;

    int ans=0,n1=0;
    stringstream ss(str);
    int t;
    while(ss>>t){
      if(t==1)n1++;
      if(t>10)t=10;
      ans+=t;
    }
    while(n1 && ans<12){
      n1--;
      ans+=10;
    }
    if(ans>21)ans=0;
    cout<<ans<<endl;
  }
}