#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

int MAX = 21;

int main()
{
    string s;
    int l, n, one = 0;

    while(getline(cin, s))
    {
        one = 0; n = 0;
        vector<int> ans;
        ans.push_back(0);

        if(s == "0") break;
        s += " ";
        int l = s.size();
        
        REP(l)if(s[i] != ' '){ n = n*10 + s[i] - '0';}
        else 
        {
            if(n == 1) one++;
            if(n >= 10) n =10;
            ans[0] += n;
            n = 0;
        }
        REP(one){ans.push_back( ans[i] + 10); }
        int maxp = 0;
        REP(ans.size())if(ans[i] > maxp && ans[i] <= MAX) maxp = ans[i];

        cout << maxp << endl;

    }
    return 0;
}