#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;

int main(){
  string str;
  while(getline(cin,str) , str != "0"){
    int sum = 0;
    int cnt = 0;
    for(int i=0;i<str.size();i++){
      if(str[i] == ' '){
      } else if(i+1 != str.size() &&  str[i+1] != ' '){
	sum += (str[i]-'0')*10;
	i++;
      } else {
	if(str[i] == '1') {
	  cnt++;
	  sum += 10;
	}
	sum += str[i]-'0';
      }
    }
    while(sum > 21 && cnt != 0){
      cnt--;
      sum -= 10;
    }
    if(sum > 21) cout << "0" << endl;
    else cout << sum << endl;
  }
}