#include<iostream>
#include<string>
using namespace std;

int fixNumberOne( int cnt, int a )
{
    if( cnt == 0 )
        return a;
    if( a + 11 <= 22 - cnt )
        return a + 10 + cnt;
    else
        return a + cnt;
}

int main()
{
    int a[128], b[100];
    for( int i = '1'; i < '1' + 9; i++ )
        a[i] = i - '0';
    a['1'+'0'] = 10;
    a['1'+'1'] = 10;
    a['1'+'2'] = 10;
    a['1'+'3'] = 10;

    string str;

    while( getline( cin, str ) )
    {
        if( str == "0" )
            break;

        str += " ";

        for( int i = 0; i < 100; i++ )
            b[i] = 0;
    
        int j = 0, sum = 0, cnt = 0;
        for( int i = 0; i < str.size(); i++ )
        {
            if( str[i] == ' ' )
            {
                if( a[sum] == 1 )
                    cnt++;
                else
                    b[j] = a[sum];
                sum = 0;
                j++;
            }
            else
                sum += str[i];
        }
        sum = 0;
        for( int i = 0; i < 100; i++ )
            if( b[i] != 1 )
                sum += b[i];
        sum = fixNumberOne( cnt, sum );

        if( sum > 21 )
            cout << 0 << endl;
        else
            cout << sum << endl;
    }

    return 0;
}
