#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string s;
  while (getline(cin, s), s != "0") {
    stringstream ss;
    ss << s;
    int sum = 0, one = 0, a;
    while (ss >> a) {
      if (a == 1) one++;
      else sum += min(10, a);
    }
    if (one > 21 || sum > 21 || one + sum > 21) {
      cout << 0 << endl;
    } else {
      int p = (11 * one + sum - 21 + 10 - 1) / 10;
      cout << p + (one - p) * 11 + sum << endl;
    }
  }

  return 0;
}
