const stdin = require("fs").readFileSync("/dev/stdin", "UTF-8");
const lines = stdin.split(/\r?\n/g).filter(x => !!x);
for (const line of lines) {
    if (line == "0") break;
    const c = line.split(" ").map(x => Math.min(10, +x));
    const ones = c.filter(x => x === 1).length;
    const s0 = c.reduce((a, b) => a + b, 0);
    let snum = 0;
    for (let i = 0; i <= ones; i++) {
        const siraw = s0 + 10 * i;
        const si = siraw > 21 ? 0 : siraw;
        snum = Math.max(snum, si);
    }
    console.log(snum);
}
