#include <bits/stdc++.h>

using namespace std;

int main()
{
  string cards;
  while(getline(cin, cards), cards != "0"){
    stringstream ss(cards);
    int ans = 0, x;
    bool one = false;
    while(ss >> x){
      ans += min(x, 10);
      if(x == 1) one = true;
    }
    if(ans > 21) cout << 0 << endl;
    else cout << (one ? ((ans + 10 <= 21) ? ans + 10 : ans) : ans) << endl;
  }
  return 0;
}