#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
  int n, p, q, s, t;
  int a[60];
  char buf[200];
  while (1) {
    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%d", &t);
    if (!t) break;
    p = n = 0;
    while (sscanf(buf+p, "%d%n", &a[n], &q) == 1) {
      ++n;
      p += q;
    }
    s = t = 0;
    for (int i=0; i<n; i++) {
      if (a[i] < 10) {
        s += a[i];
        if (a[i] == 1) {
          ++t;
        }
      } else {
        s += 10;
      }
    }
    if (s > 21) {
      s = 0;
    } else {
      s += 10 * min(t, (21-s)/10);
    }
    printf("%d\n", s);
  }
  return 0;
}