#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  string in;
  while(getline(cin,in)){
    if(in=="0") break;
    vector<int> num;
    stringstream ss(in);
    int tmp;
    while(ss>>tmp) num.push_back(tmp);
    int ace = 0;
    int ans = 0;
    REP(i,num.size()){
      if(num[i]>10) num[i] = 10;
      if(num[i]==1){
        ace++;
        num[i] = 11;
      }
      ans += num[i];
    }
    while(ace&&ans>21){
      ace--;
      ans-=10;
    }
    cout<<((ans>21)?0:ans)<<endl;
  }
  return 0;
}