#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cctype>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < (n) ; ++i )
vector<int>card;
int ans;
void bfs(int now,int sum){
  if(sum > 21) return;
  if(now == card.size()){
    ans = max(ans,sum);
    return;
  }
  bfs(now+1,sum+min(card[now],10));
  if(card[now] == 1) bfs(now+1,sum+11);
}
int main(){
  string s;
  while(getline(cin,s) , s != "0"){
    card.clear();
    ans = 0;
    int a = 0;
    rep(i,s.size()){
      if(isdigit(s[i])) a = a * 10 + s[i] - '0';
      else if(s[i] == ' '){
        card.push_back(a);
        a = 0;
      }
    }
    card.push_back(a);

    bfs(0,0);
    cout << ans << endl;
  }
}