#include <iostream>
using namespace std;

int main()
{
  string str;

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

    int sum = 0;
    int cnt = 0;

    for (int i = 0; i < str.size(); i++){
      if (str[i] == '1' && '0' <= str[i + 1] && str[i + 1] <= '3'){
        sum += 10;
        i++;
        continue;
      }
      if (str[i] == '1') cnt++;
      if (str[i] != ' ') sum += (str[i] - '0');
    }


    while(cnt--){
      if (sum + 10 <= 21){
        sum += 10;
      }
    }
   if (sum > 21){
      sum = 0;
    }

   cout << sum << endl;
  }
}