#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int a[512], p;

int dfs(int n, int c){
  if(n > 21) return 0;
  if(c == p) return n;
  if(a[c] == 1) return max(dfs(n+1, c+1), dfs(n+11, c+1));
  if(a[c] > 10) return dfs(n+10, c+1);
  return dfs(n+a[c], c+1);
}

int main(){
  char str[512];
  while(fgets(str, sizeof(str), stdin) && str[0] != '0'){
    memset(a, 0, sizeof(a));
    char *tp;
    p = 0;
    tp = strtok(str, " ");
    while(tp != NULL){
      a[p++] = atoi(tp);
      tp = strtok(NULL, " ");
    }

    printf("%d\n", dfs(0, 0));
  }
  return 0;
}