n = gets.split(" ").map{|k| k.to_i}
until n[0] == 0
    index = []
    for i in 0..n.length-1 do
        if n[i] > 10
            index << i
        end
    end
    if index.empty?
    else
        index.each do |index|
             n[index] = 10
        end
    end
    sum = n.sum
    one = 0
    if n.include?(1)
        one = 1
    end
    if sum > 21
        sum = 0
    elsif sum <= 11 && one == 1
        sum += 10
    end

    puts sum
    n = gets.split(" ").map{|k| k.to_i}
end

