#include <iostream>
#include <sstream>
using namespace std;
main()
{
    string s;
    while( getline( cin, s ), s != "0" )
    {
        stringstream ss(s);
        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;
}
