loop do
    a = gets.split.map(&:to_i).map {|x| x > 10 ? 10 : x}
    break if a == [0]
    s = a.inject(:+)
    ace = a.count(1)
    while ace > 0 and s + 10 <= 21
        s += 10
        ace -= 0
    end
    if s > 21
        puts 0
    else
        puts s
    end
end
