#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <cstdlib>
using namespace std;

int main(){
  int i,j,n,ans,one;
  string line;
  while(1){
    getline(cin,line);
    if(line == "0") break;
    stringstream sin(line);
    string str;
    ans = 0;
    one = 0;
    while(sin >> str){
      n = atoi(str.c_str()) * 1;
      if(n > 10) n = 10;
      ans += n;
      if(n == 1 && ans <= 11){
	ans += 10;
	one++;
      }

      if(ans > 21){
	if(one > 0){
	  one--;
	  ans -= 10;
	}
	else{
	  ans = 0;
	  break;
	}
      }
    }
    cout << ans << endl;

  }
  return 0;
}