loop do
  cs = gets.split.map(&:to_i)
  break if cs == [0]
  cs.map! {|c| c >= 10 ? 10 : c }
  s = cs.inject 0, :+
  r = s <= 21 ? s : 0
  cs.count {|c| c == 1 }.times do |i|
    s += 10
    r = s if s <= 21
  end
  p r
end