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

int main() {
    string s;
    while (getline(cin, s), s != "0") {
        stringstream ss(s);
        int n, sum = 0, one = 0;
        while (ss >> n) {
            sum += (10 <= n ? 10 : n);
            if (n == 1) ++ one;
        }
        int res = 0;
        for (int i=0; i<=one; ++i) {
            if (21 < sum + 10 * i) break;
            res = max(res, sum + 10 * i);
        }
        cout << res << endl;
    }
    return 0;
}